我正在尝试使用电子邮件意图发送电子邮件。这是我的代码:
/** Called when the user clicks the send button */
public void cont_sendEmail(View view) {
final EditText nick = (EditText) findViewById(R.id.contNick);
final EditText feas = (EditText) findViewById(R.id.contFeas);
final EditText tip = (EditText) findViewById(R.id.contTip);
String totalNick = nick.getText().toString();
String totalFeas = feas.getText().toString();
String totalTip = tip.getText().toString();
String totalText = totalNick.concat(totalFeas);
// Do something in response to button
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"sando@live.se"});
i.putExtra(Intent.EXTRA_SUBJECT, "New contribution!");
i.putExtra(Intent.EXTRA_TEXT , totalText);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(ContributeActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
当我按下“发送”按钮并激活 cont_sendEmail 时,应用程序崩溃。这是我的日志:
08-17 14:29:16.445: E/AndroidRuntime(12649): FATAL EXCEPTION: main
08-17 14:29:16.445: E/AndroidRuntime(12649): java.lang.IllegalStateException: Could not execute method of the activity
08-17 14:29:16.445: E/AndroidRuntime(12649): at android.view.View$1.onClick(View.java:3691)
08-17 14:29:16.445: E/AndroidRuntime(12649): at android.view.View.performClick(View.java:4211)
08-17 14:29:16.445: E/AndroidRuntime(12649): at android.view.View$PerformClick.run(View.java:17267)
08-17 14:29:16.445: E/AndroidRuntime(12649): at android.os.Handler.handleCallback(Handler.java:615)
08-17 14:29:16.445: E/AndroidRuntime(12649): at android.os.Handler.dispatchMessage(Handler.java:92)
08-17 14:29:16.445: E/AndroidRuntime(12649): at android.os.Looper.loop(Looper.java:137)
08-17 14:29:16.445: E/AndroidRuntime(12649): at android.app.ActivityThread.main(ActivityThread.java:4898)
08-17 14:29:16.445: E/AndroidRuntime(12649): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 14:29:16.445: E/AndroidRuntime(12649): at java.lang.reflect.Method.invoke(Method.java:511)
08-17 14:29:16.445: E/AndroidRuntime(12649): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
08-17 14:29:16.445: E/AndroidRuntime(12649): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
08-17 14:29:16.445: E/AndroidRuntime(12649): at dalvik.system.NativeStart.main(Native Method)
08-17 14:29:16.445: E/AndroidRuntime(12649): Caused by: java.lang.reflect.InvocationTargetException
08-17 14:29:16.445: E/AndroidRuntime(12649): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 14:29:16.445: E/AndroidRuntime(12649): at java.lang.reflect.Method.invoke(Method.java:511)
08-17 14:29:16.445: E/AndroidRuntime(12649): at android.view.View$1.onClick(View.java:3686)
08-17 14:29:16.445: E/AndroidRuntime(12649): ... 11 more
08-17 14:29:16.445: E/AndroidRuntime(12649): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
08-17 14:29:16.445: E/AndroidRuntime(12649): at com.sandtdevelopment.getrich.ContributeActivity.cont_sendEmail(ContributeActivity.java:18)
(如何粘贴 logcat 以使其可读?)
可能是什么问题?