我的申请有问题。我认为我有一个类可以正确放置值并且可以正常工作,但是当我尝试获取捆绑包中的类的值时,出现此错误:
04-16 02:59:12.900: E/AndroidRuntime(1443): FATAL EXCEPTION: main
04-16 02:59:12.900: E/AndroidRuntime(1443): Process: com.example.en4dis, PID: 1443
04-16 02:59:12.900: E/AndroidRuntime(1443): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.en4dis/com.example.en4dis.activitySelectEnvironment}: java.lang.ClassCastException: java.lang.Object[] cannot be cast to com.example.en4dis.Point[]
04-16 02:59:12.900: E/AndroidRuntime(1443): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
04-16 02:59:12.900: E/AndroidRuntime(1443): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
04-16 02:59:12.900: E/AndroidRuntime(1443): at android.app.ActivityThread.access$700(ActivityThread.java:135)
04-16 02:59:12.900: E/AndroidRuntime(1443): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
04-16 02:59:12.900: E/AndroidRuntime(1443): at android.os.Handler.dispatchMessage(Handler.java:102)
04-16 02:59:12.900: E/AndroidRuntime(1443): at android.os.Looper.loop(Looper.java:137)
04-16 02:59:12.900: E/AndroidRuntime(1443): at android.app.ActivityThread.main(ActivityThread.java:4998)
04-16 02:59:12.900: E/AndroidRuntime(1443): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 02:59:12.900: E/AndroidRuntime(1443): at java.lang.reflect.Method.invoke(Method.java:515)
04-16 02:59:12.900: E/AndroidRuntime(1443): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
04-16 02:59:12.900: E/AndroidRuntime(1443): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
04-16 02:59:12.900: E/AndroidRuntime(1443): at dalvik.system.NativeStart.main(Native Method)
04-16 02:59:12.900: E/AndroidRuntime(1443): Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to com.example.en4dis.Point[]
04-16 02:59:12.900: E/AndroidRuntime(1443): at com.example.en4dis.activitySelectEnvironment.onCreate(activitySelectEnvironment.java:108)
04-16 02:59:12.900: E/AndroidRuntime(1443): at android.app.Activity.performCreate(Activity.java:5243)
04-16 02:59:12.900: E/AndroidRuntime(1443): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-16 02:59:12.900: E/AndroidRuntime(1443): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
04-16 02:59:12.900: E/AndroidRuntime(1443): ... 11 more
这个错误出现在这一行:
points = (Point[]) myBundle.get("puntos");
我使用这段代码来声明我的 Point 数组:
Point points[];
我使用这个其他代码将它放在我的包中:
myIntent.putExtra("puntos", points);
我将我的 Point 类代码用于更多说明:
package com.example.en4dis;
public class Point implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = -4910520794768384111L;
String _id;
String _comment;
String _calification;
String _coords;
int _X;
int _Y;
public Point(String id, String comment, String calification, String coords, int x, int y)
{
_id = id;
_comment = comment;
_calification = calification;
_coords = coords;
_X = x;
_Y = y;
}
public String getID()
{
return _id;
}
public String getComment()
{
return _comment;
}
public String getCalification()
{
return _calification;
}
public String getCoords()
{
return _coords;
}
public int getPointX()
{
return _X;
}
public int getPointY()
{
return _Y;
}
}
Eclipse抛出了一个异常,我必须把“private static final long serialVersionUID = -4910520794768384111L;” 线来修复它,我不知道这条线是问题还是什么。有人能帮我吗?谢谢!