因此,我按照本教程进行操作,以便我的应用可以接收内容。但是当我尝试向我的应用程序分享某些内容时,它会崩溃。
这是代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent);
}
else {
}
}
}
void handleSendText (Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
//Display definition. Use HTTP GET for Wikitonary.
CardUI mCardView = (CardUI) findViewById(R.id.cardsview);
mCardView.setSwipeable(true);
//mCardView.addCard(new MyCard("1 card"));
}
}
当它崩溃时,它会抛出所有这些错误:
01-18 17:24:34.735: E/AndroidRuntime(1937): FATAL EXCEPTION: main
01-18 17:24:34.735: E/AndroidRuntime(1937): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dictionary/com.example.dictionary.MainActivity}: java.lang.NullPointerException
01-18 17:24:34.735: E/AndroidRuntime(1937): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-18 17:24:34.735: E/AndroidRuntime(1937): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-18 17:24:34.735: E/AndroidRuntime(1937): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-18 17:24:34.735: E/AndroidRuntime(1937): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-18 17:24:34.735: E/AndroidRuntime(1937): at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 17:24:34.735: E/AndroidRuntime(1937): at android.os.Looper.loop(Looper.java:137)
01-18 17:24:34.735: E/AndroidRuntime(1937): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-18 17:24:34.735: E/AndroidRuntime(1937): at java.lang.reflect.Method.invokeNative(Native Method)
01-18 17:24:34.735: E/AndroidRuntime(1937): at java.lang.reflect.Method.invoke(Method.java:511)
01-18 17:24:34.735: E/AndroidRuntime(1937): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-18 17:24:34.735: E/AndroidRuntime(1937): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-18 17:24:34.735: E/AndroidRuntime(1937): at dalvik.system.NativeStart.main(Native Method)
01-18 17:24:34.735: E/AndroidRuntime(1937): Caused by: java.lang.NullPointerException
01-18 17:24:34.735: E/AndroidRuntime(1937): at com.example.dictionary.MainActivity.handleSendText(MainActivity.java:42)
01-18 17:24:34.735: E/AndroidRuntime(1937): at com.example.dictionary.MainActivity.onCreate(MainActivity.java:29)
01-18 17:24:34.735: E/AndroidRuntime(1937): at android.app.Activity.performCreate(Activity.java:5104)
01-18 17:24:34.735: E/AndroidRuntime(1937): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-18 17:24:34.735: E/AndroidRuntime(1937): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-18 17:24:34.735: E/AndroidRuntime(1937): ... 11 more
01-18 17:24:43.078: I/Process(1937): Sending signal. PID: 1937 SIG: 9
谁能告诉我有什么问题?