2013-03-22 1 views
3

android intent를 사용하여 이메일을 보내려고합니다. 모든 것은 null 값을 얻지 만 null 값을받는 필드로 보내기에서 전자 메일 앱을 선택할 때를 제외하고는 잘 작동하지만 null 값을 확인했지만 문자열이 null 인 경우이를 감지 할 수없는 것처럼 보입니다. 아무도 내가이 문제를 해결할 수 있도록 도와 줄 수 있습니까?null 인 경우 Android에서 문자열을 찾을 수 없습니다.

if (emailAddress[0]!=null && !emailAddress[0].isEmpty()) { 
       Intent intent = new Intent(Intent.ACTION_SEND); 
       intent.setType("text/plain"); 
       intent.putExtra(Intent.EXTRA_EMAIL, emailAddress); 
       intent.putExtra(Intent.EXTRA_SUBJECT, 
         getResources().getString(R.string.email_sub)); 
       // intent.putExtra(Intent.EXTRA_TEXT, "I'm email body."); 

       startActivity(Intent.createChooser(intent, "Send Email")); 
+0

) { return string! = null &&! string.isEmpty() &&! string.trim(). isEmpty(); } – TronicZomB

+1

사용이 ... 공공 정적 부울 isNotNullNotEmptyNotWhiteSpaceOnlyByJava ( 최종 문자열 문자열이 될 수 있다고 생각하지 않습니다 – itsrajesh4uguys

답변

2

확인 등호() 또는 equalsingorecase와 문자열(); 이것을 사용하는

String[] emailAddress = new String[10]; 

      emailAddress[0]="asdfasdfasdfasdf"; 

      if (emailAddress[0]!=null && !emailAddress[0].isEmpty()) 
      { 
       System.err.println("asddddddd " +emailAddress[0]); 
      } 
+0

tryed equals()가 작동했지만 작동하지 않음 –

+0

http://stackoverflow.com/questions/2920525/how-to-check-a-string-against-null-in-java보세요 – itsrajesh4uguys

2

시도 당신은 String이 비어 있거나 null의 경우 감지 TextUtils.isEmpty(CharSequence str) 방법을 사용할 수 있습니다 널 (null)과 빈 문자열을

if(!TextUtils.isEmpty(emailAddress[0])) 
0

TextUtils.isEmpty (CharSequence를 숯불) 작동하지 않는 경우 null String에 사용되며 emailAddress [0] 위치 값이 null이고 배열이 null이기 때문에 if (emailAddress! = null)을 확인하십시오. 당신이

if (emailAddress[0].toString().equals("")) 

2 이하 또는

if (emailAddress[0].toString().length() > 0) 
0

당신을 도움이 될 수는 .. 널 (null)하지 않을 수 있습니다. AFAIK Intent.EXTRA_EMAIL 두 번째 인수로 문자열 배열을 사용합니다.

시도해보십시오.

String[] addressArray = {"[email protected]", "[email protected]"}; 

//some lines... 

intent.putExtra(Intent.EXTRA_EMAIL, addressArray); 
나는이`! EMAILADDRESS [0] .isEmpty()가`필요 ... 내가 잘못 생각 ...
+0

.toString () 모든 문제를 만드는 부분이었다 .. 감사합니다 –

0

문자열에서 하나를 사용할 수 있습니다

+0

OP는 두 번째 매개 변수로'String []'을 전달합니다. – jprofitt

+0

@jprofit 제 잘못입니다. 나는 emailAddresses 또는 emailAdressArray를 볼 것으로 예상했다. – akaya

관련 문제