从按钮发送邮件时,单击我的设备会显示错误。这会在logcat中抛出SuperNotCalledException
我在这里发布代码和logcat输出。
代码
Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
String recosubject = getString(R.string.recoSub);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, ""
+ recosubject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, ""
+ reco);
startActivity(Intent.createChooser(intent, "Send mail..."));
这是logcat输出
Uncaught handler: thread main exiting due to uncaught exception
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): android.app.SuperNotCalledException: Activity {android/com.android.internal.app.ChooserActivity} did not call through to super.onCreate()
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2461)
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at android.os.Handler.dispatchMessage(Handler.java:99)
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at android.os.Looper.loop(Looper.java:123)
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at android.app.ActivityThread.main(ActivityThread.java:4367)
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at java.lang.reflect.Method.invokeNative(Native Method)
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at java.lang.reflect.Method.invoke(Method.java:521)
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-29 15:29:14.488: ERROR/AndroidRuntime(6823): at dalvik.system.NativeStart.main(Native Method)
有人能说出这段代码出了什么问题吗?
答案 0 :(得分:2)
让解决方案成为我的自我......这只是一个愚蠢的错误,感谢Marcovena和Saurabh指出它。两个都是+1。
这就是我所做的改变
Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
String recosubject = getString(R.string.recoSub);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, ""
+ recosubject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, ""
+ reco);
而不是这一行
startActivity(Intent.createChooser(intent, "Send mail..."));
我改变了这个
startActivity(emailIntent);
它有效。
感谢你们俩指出这个愚蠢的错误。
答案 1 :(得分:1)
在ChooseActivity的onCreate方法中,将其添加为第一行
super.onCreate(savedInstanceState);
答案 2 :(得分:1)
startActivity(Intent.createChooser(intent,“Send mail ...”)); b / w emailintent 和 intent 变量有什么区别?还是只是一个错字?