使用意图导致崩溃共享链接

时间:2018-04-03 14:36:36

标签: android android-intent

我正在尝试使用intent发送链接。但点击分享按钮后,应用程序崩溃了。这是我的代码

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "example.com");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Check out this site!");
startActivity(Intent.createChooser(intent, "Share Using"));

这是logcat报告

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.net.Uri.writeToParcel(android.os.Parcel, int)' on a null object reference
          at android.app.ActivityManagerProxy.grantUriPermission(ActivityManagerNative.java:4830)
          at android.content.Intent.migrateExtraStreamToClipData(Intent.java:9195)
          at android.app.Instrumentation.execStartActivity(Instrumentation.java:1529)
          at android.app.Activity.startActivityForResult(Activity.java:4391)
          at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
          at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
          at android.app.Activity.startActivityForResult(Activity.java:4335)
          at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
          at android.app.Activity.startActivity(Activity.java:4702)
          at android.app.Activity.startActivity(Activity.java:4670)
          at com.dualbrotech.autocontactbackup.ui.HomeActivity.onNavigationItemSelected(HomeActivity.java:238)
          at android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:154)
          at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
          at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
          at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
          at android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:342)
          at android.view.View.performClick(View.java:5646)
          at android.view.View$PerformClick.run(View.java:22473)
          at android.os.Handler.handleCallback(Handler.java:761)
          at android.os.Handler.dispatchMessage(Handler.java:98)
          at android.os.Looper.loop(Looper.java:156)
          at android.app.ActivityThread.main(ActivityThread.java:6523)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)

我该如何解决这个问题?

0 个答案:

没有答案