通过Android发送电子邮件

时间:2017-05-07 21:27:42

标签: android email android-intent

我想从我的应用程序发送一封电子邮件,我不断收到此异常 -

/AndroidRuntime: FATAL EXCEPTION: main                                                                       Process: com.example.user.trackyournevi, PID: 4220
java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
at android.app.Activity.startActivityForResult(Activity.java:4283)    
at android.app.Activity.startActivityForResult(Activity.java:4230)
at android.app.Activity.startActivity(Activity.java:4567)
at android.app.Activity.startActivity(Activity.java:4535)
at com.example.user.trackyournevi.services.CommaSeparatedValues.sentAttachedMail(CommaSeparatedValues.java:88)
                                                                              at com.example.user.trackyournevi.services.CommaSeparatedValues.handleActionExport(CommaSeparatedValues.java:47)
                                                                              at com.example.user.trackyournevi.MainActivity.onNavigationItemSelected(MainActivity.java:125)
                                                                              at android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:151)
                                                                              at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)
                                                                              at android.support.v7.view.menu.SubMenuBuilder.dispatchMenuItemSelected(SubMenuBuilder.java:84)
                                                                              at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
                                                                              at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
                                                                              at android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:318)
                                                                              at android.view.View.performClick(View.java:5697)
                                                                              at android.view.View$PerformClick.run(View.java:22526)
                                                                              at android.os.Handler.handleCallback(Handler.java:739)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                              at android.os.Looper.loop(Looper.java:158)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:7224)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

此意图的代码是 -

Intent email = new Intent(Intent.ACTION_SENDTO);
email.setType("plain/text");
email.putExtra(Intent.EXTRA_SUBJECT, "My Scannings");
email.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
email.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(email , "Email:"));

我检查了这个参数的非零值。

请帮帮我

0 个答案:

没有答案