我想從服務器應用程序發送一個對象到Android客戶端。所有的類都在同一個包和eclipse中的src文件夾中,包括導致ClassNotFoundException:CardGame的那個類。我是新來的android和相當新的Java,並已堅持了這一兩天,所以我想知道如果有人能夠幫助我找出問題是什麼...Android ClassNotFoundException與ObjectInputStream
這是導致該問題的代碼...
CardGame game = (CardGame) in.readObject();
這裏是堆棧跟蹤...
04-21 19:21:35.608: W/System.err(482): java.lang.ClassNotFoundException: CardGame
04-21 19:21:35.618: W/System.err(482): at java.lang.Class.classForName(Native Method)
04-21 19:21:35.618: W/System.err(482): at java.lang.Class.forName(Class.java:235)
04-21 19:21:35.618: W/System.err(482): at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2590)
04-21 19:21:35.618: W/System.err(482): at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1846)
04-21 19:21:35.618: W/System.err(482): at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:826)
04-21 19:21:35.618: W/System.err(482): at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2066)
04-21 19:21:35.618: W/System.err(482): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:929)
04-21 19:21:35.628: W/System.err(482): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2285)
04-21 19:21:35.628: W/System.err(482): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2240)
04-21 19:21:35.628: W/System.err(482): at com.client.activity.play.init(play.java:107)
04-21 19:21:35.628: W/System.err(482): at com.client.activity.play.onCreate(play.java:54)
04-21 19:21:35.628: W/System.err(482): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-21 19:21:35.628: W/System.err(482): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-21 19:21:35.628: W/System.err(482): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-21 19:21:35.628: W/System.err(482): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-21 19:21:35.628: W/System.err(482): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-21 19:21:35.638: W/System.err(482): at android.os.Handler.dispatchMessage(Handler.java:99)
04-21 19:21:35.638: W/System.err(482): at android.os.Looper.loop(Looper.java:123)
04-21 19:21:35.638: W/System.err(482): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-21 19:21:35.638: W/System.err(482): at java.lang.reflect.Method.invokeNative(Native Method)
04-21 19:21:35.638: W/System.err(482): at java.lang.reflect.Method.invoke(Method.java:521)
04-21 19:21:35.638: W/System.err(482): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-21 19:21:35.638: W/System.err(482): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-21 19:21:35.648: W/System.err(482): at dalvik.system.NativeStart.main(Native Method)
04-21 19:21:35.648: W/System.err(482): Caused by: java.lang.NoClassDefFoundError: CardGame
04-21 19:21:35.648: W/System.err(482): ... 24 more
04-21 19:21:35.658: W/System.err(482): Caused by: java.lang.ClassNotFoundException: CardGame in loader dalvik.system.PathClassLoader[/data/app/com.client.activity-1.apk]
04-21 19:21:35.658: W/System.err(482): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-21 19:21:35.668: W/System.err(482): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-21 19:21:35.668: W/System.err(482): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-21 19:21:35.668: W/System.err(482): ... 24 more
謝謝!
謝謝。如果我所做的只是聲明CardGame遊戲;那麼沒有錯誤報告。我怎麼才能讓android正確構建APK? – Matt 2012-04-21 20:24:12