在我的应用程序中,我使用SharCompat获取我要分享内容的应用程序列表。我在列表中有twitter应用程序。当我去设备中的twitter应用程序。我有以下例外。
打开共享内容的应用程序列表,我使用了以下代码
ShareCompat.IntentBuilder builder = ShareCompat.IntentBuilder.from(Myactivity.this);
builder.setType("text/plain");
Intent i = builder.getIntent();
startActivity(Intent.createChooser(i, "test"));
在打开Twitter应用程序页面时,我有以下例外
06-20 02:10:49.205: E/AndroidRuntime(15402): java.lang.RuntimeException: Unable to destroy activity {com.twitter.android/com.twitter.android.PostActivity}: java.lang.NullPointerException
06-20 02:10:49.205: E/AndroidRuntime(15402): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3112)
06-20 02:10:49.205: E/AndroidRuntime(15402): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3130)
06-20 02:10:49.205: E/AndroidRuntime(15402): at android.app.ActivityThread.access$1200(ActivityThread.java:123)
06-20 02:10:49.205: E/AndroidRuntime(15402): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1180)
06-20 02:10:49.205: E/AndroidRuntime(15402): at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 02:10:49.205: E/AndroidRuntime(15402): at android.os.Looper.loop(Looper.java:137)
06-20 02:10:49.205: E/AndroidRuntime(15402): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-20 02:10:49.205: E/AndroidRuntime(15402): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 02:10:49.205: E/AndroidRuntime(15402): at java.lang.reflect.Method.invoke(Method.java:511)
06-20 02:10:49.205: E/AndroidRuntime(15402): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-20 02:10:49.205: E/AndroidRuntime(15402): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-20 02:10:49.205: E/AndroidRuntime(15402): at dalvik.system.NativeStart.main(Native Method)
06-20 02:10:49.205: E/AndroidRuntime(15402): Caused by: java.lang.NullPointerException
06-20 02:10:49.205: E/AndroidRuntime(15402): at com.twitter.android.PostActivity.onDestroy(Twttr:739)
06-20 02:10:49.205: E/AndroidRuntime(15402): at android.app.Activity.performDestroy(Activity.java:4656)
06-20 02:10:49.205: E/AndroidRuntime(15402): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1079)
06-20 02:10:49.205: E/AndroidRuntime(15402): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3099)
请帮助解决此问题 。 感谢
答案 0 :(得分:1)
此代码适用于我:
Intent shareIntent = ShareCompat.IntentBuilder
.from(LocalCharadeActivity.this).setType("text/plain")
.setText("lalal").getIntent();
startActivity(shareIntent);