2014-04-16 47 views
0

我正在通過EditText收取電子郵件地址。我收到一個錯誤,說這個地址包含空格,沒有問題。我實現了address.removeAll(「\\ s」,「」);現在正在錯誤非法字符刪除空格後刪除電子郵件地址

  • 9月4日至一十六日:37:43.009:W/System.err的(1632):javax.mail.internet.AddressException:非法字符在本地名字符串``606#7f080011app :id/enterEmail}''

這裏是我的代碼捕獲電子郵件和轉換爲字符串。

 EditText e = (EditText) findViewById(R.id.enterEmail); 

     String to = e.toString().replaceAll("\\s", ""); 

在這裏我用的地址,並得到了錯誤的行:

msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(to)); 

我已經做了一些研究,試圖找到,如果它是一個解析問題,或者會是什麼引起,但一無所獲。有人知道我爲什麼會得到這個錯誤?提前致謝。

+0

什麼是電子的價值? – cybersam

+0

在這種情況下,它只是一個簡單的雅虎電子郵件地址:[email protected] – STLCards77

回答

1

這是因爲您正在將您的EditText轉換爲String而不是獲取其文本並對其執行replaceAll()

只需更換這一點:

String to = e.toString().replaceAll("\\s", ""); 

有了這個:

String to = e.getText().toString().replaceAll("\\s", ""); 
+1

然後只需使用:'e.getText()。toString()。replaceAll(...)' – nKn

+0

謝謝。給我幾分鐘,我會接受答案。 – STLCards77