在 Android 应用程序中,我试图从 Bundle 中提取额外的内容,如下所示:
Parcelable p = intent.getExtras().getParcelable("android.nfc.extra.NDEF_MESSAGES");
但我得到以下异常
Key android.nfc.extra.NDEF_MESSAGES expected Parcelable but value was a [Landroid.os.Parcelable;. The default value <null> was returned.
Attempt to cast generated internal exception:
java.lang.ClassCastException: android.os.Parcelable[] cannot be cast to android.os.Parcelable
at android.os.Bundle.getParcelable(Bundle.java:1179)
at com.example.nfcmessenger.MainActivity.onNewIntent(MainActivity.java:77)
at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1154)
at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2299)
at android.app.ActivityThread.performNewIntents(ActivityThread.java:2312)
at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2321)
at android.app.ActivityThread.access$1400(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
这是什么Landroid.os.Parcelable
?Parcelable 的正常导入只是android.os.Parcelable
.