我不确定如何解决这个问题,因为我的代码是 String[] 而不是 Object[] 我将如何解决这个错误?
这是完整的 logcat:
06-14 00:25:40.356: W/dalvikvm(13023): threadid=1: thread exiting with uncaught exception (group=0x40aa41f8)
06-14 00:25:40.356: E/AndroidRuntime(13023): FATAL EXCEPTION: main
06-14 00:25:40.356: E/AndroidRuntime(13023): java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[]
06-14 00:25:40.356: E/AndroidRuntime(13023): at com.example.drawingarrays.OutPutConversion.Out(OutPutConversion.java:7)
06-14 00:25:40.356: E/AndroidRuntime(13023): at com.example.drawingarrays.MainActivity.onClick(MainActivity.java:64)
06-14 00:25:40.356: E/AndroidRuntime(13023): at android.view.View.performClick(View.java:3540)
06-14 00:25:40.356: E/AndroidRuntime(13023): at android.view.View$PerformClick.run(View.java:14167)
06-14 00:25:40.356: E/AndroidRuntime(13023): at android.os.Handler.handleCallback(Handler.java:605)
06-14 00:25:40.356: E/AndroidRuntime(13023): at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 00:25:40.356: E/AndroidRuntime(13023): at android.os.Looper.loop(Looper.java:137)
06-14 00:25:40.356: E/AndroidRuntime(13023): at android.app.ActivityThread.main(ActivityThread.java:4586)
06-14 00:25:40.356: E/AndroidRuntime(13023): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 00:25:40.356: E/AndroidRuntime(13023): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 00:25:40.356: E/AndroidRuntime(13023): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-14 00:25:40.356: E/AndroidRuntime(13023): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-14 00:25:40.356: E/AndroidRuntime(13023): at dalvik.system.NativeStart.main(Native Method)
这是我的代码:
public class OutPutConversion {
DrawingTools GAL = new DrawingTools();
public void Out() {
String[] Result = (String[]) GAL.getAL().toArray();
float[] vertices = new float[Result.length];
for (int i = 0; i < vertices.length; i++) {
vertices[i] = Float.valueOf(Result[i]);
}
}
}
这是绘图工具类:
public class DrawingTools {
ArrayList<String> AL = new ArrayList<String>();
public ArrayList<String> getAL() {
return AL;
}
public void AddLine(String Input1) {
String[] pStrings = Input1.split(",");
for (int i = 0; i < pStrings.length; i++) {
AL.add(pStrings[i]);
}
}