Results 1 to 3 of 3
  1. #1
    AtlDynasty25 is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default ClassNotFoundException with ObjectInputStream

    Hey all, I'm new to android, and fairly new to Java as well, although I know my way around it a bit.

    I am trying to send an object from a server program on my pc to a client on an android device. I have been stuck with a problem for a couple of days now... I can't understand why I am getting a ClassNotFoundException when trying to read in the object.

    Java Code:
    CardGame game = (CardGame)in.readObject();
    Is causing the problem. I can create a CardGame object without issue. It's only when I try to read in the CardGameObject which has been sent from the server that I get the exception.

    Here is the stack trace...

    Java Code:
    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
    I am at a loss, so any help would be greatly appreciated. Thank you!

  2. #2
    AtlDynasty25 is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Re: ClassNotFoundException with ObjectInputStream

    Turns out that the class of the object that is being sent through the ObjectOutputStream must have the same package name on both the server, and on the client device. This seems to have fixed my problem.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Problem With ObjectInputStream
    By shomid in forum Networking
    Replies: 1
    Last Post: 08-29-2011, 05:12 PM
  2. ObjectInputStream and the Serializable class
    By Junky in forum Advanced Java
    Replies: 5
    Last Post: 08-15-2011, 02:46 PM
  3. ObjectInputStream issue
    By aianta in forum New To Java
    Replies: 8
    Last Post: 04-13-2011, 02:22 AM
  4. ObjectInputStream does not initialize
    By Singing Boyo in forum New To Java
    Replies: 1
    Last Post: 06-03-2009, 09:11 AM
  5. Reading from ObjectInputStream
    By deepthought015 in forum Networking
    Replies: 8
    Last Post: 04-28-2009, 06:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •