我的应用程序有问题。我认为我有一个可以正确放置值并可以正常工作的类,但是当我尝试获取捆绑销售的类的值时,出现此错误:

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;”线来修复它,我不知道这是问题还是什么。有人能帮我吗?谢谢!

最佳答案

你试一试,

更换

points = (Point[]) myBundle.get("puntos");




Object[] objects = myBundle.get("puntos");
points = Arrays.copyOf(objects ,objects.length, Point[].class);


让我知道会发生什么。

关于java - 无法开始 Activity ,我自己的课遇到了麻烦,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23106047/

10-10 02:23