您好我是Android新手任何人都可以帮我解决这个错误...
我的代码看起来像
wheelArrayList = (ArrayList<String>) bundle.get("listData");
logcat的:
03-15 18:29:54.967: E/AndroidRuntime(527): FATAL EXCEPTION: main
03-15 18:29:54.967: E/AndroidRuntime(527): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pack.customadpterforendless/com.pack.customadpterforendless.MainActivity}: java.lang.ClassCastException: java.lang.String
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.os.Handler.dispatchMessage(Handler.java:99)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.os.Looper.loop(Looper.java:123)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-15 18:29:54.967: E/AndroidRuntime(527): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 18:29:54.967: E/AndroidRuntime(527): at java.lang.reflect.Method.invoke(Method.java:521)
03-15 18:29:54.967: E/AndroidRuntime(527): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-15 18:29:54.967: E/AndroidRuntime(527): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-15 18:29:54.967: E/AndroidRuntime(527): at dalvik.system.NativeStart.main(Native Method)
03-15 18:29:54.967: E/AndroidRuntime(527): Caused by: java.lang.ClassCastException: java.lang.String
03-15 18:29:54.967: E/AndroidRuntime(527): at com.pack.customadpterforendless.MainActivity.onCreate(MainActivity.java:42)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-15 18:29:54.967: E/AndroidRuntime(527): ... 11 more
答案 0 :(得分:3)
你应该使用
getIntent().getXXXArrayListExtra("Name");
其中XXX表示ArraList包含的对象类型,例如,如果您的ArrayList是字符串列表,则使用
getIntent().getStringArrayListExtra("Name");