Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > writeObject and readObject problem

Reply
Thread Tools

writeObject and readObject problem

 
 
Andrew Thompson
Guest
Posts: n/a
 
      09-22-2004
On Wed, 22 Sep 2004 04:40:46 -0400, juicy wrote:

> I am using Microsoft VM instead of JVM, is the exception because of no
> certain class in Microsoft VM?


I think the stacktrace and SSCCE will best determine that.

OTOH, if you have a self-contained piece of code <10Kb,
you can check it against the 1.1 VM (either 1.1.8[1] or
specifically the MSVM[2]) at the Java On-Line Compiler.

[1] <http://www.physci.org/javac.jsp?bcp=11>
[2] <http://www.physci.org/javac.jsp?bcp=MS>

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
 
Reply With Quote
 
 
 
 
juicy
Guest
Posts: n/a
 
      09-23-2004
So terrible i get message like this
java.lang.ClassNotFoundException
at java/io/ObjectInputStream.loadClass0
at java/io/ObjectInputStream.resolveClass
at java/io/ObjectInputStream.readClassDescriptor
at java/io/ObjectInputStream.readNewObject
at java/io/ObjectInputStream.readObject
at java/io/ObjectInputStream.goToEndOfBlockData
at java/io/ObjectInputStream.readNewObject
at java/io/ObjectInputStream.readObject
at com/ms/!!!Internal_Class_0.DefaultReadMethod
at java/io/ObjectInputStream.invokeDefaultReadObject
at java/io/ObjectInputStream.defaultReadObject
at java/io/ObjectInputStream.readNewObject
at java/io/ObjectInputStream.readObject
at MainVirtual.run
at java/lang/Thread.run

What should i do now?

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      09-23-2004
On Thu, 23 Sep 2004 04:45:40 -0400, juicy wrote:
> So terrible i get message like this
> java.lang.ClassNotFoundException
> at java/io/ObjectInputStream.loadClass0
> at java/io/ObjectInputStream.resolveClass
> at java/io/ObjectInputStream.readClassDescriptor
> at java/io/ObjectInputStream.readNewObject
> at java/io/ObjectInputStream.readObject
> at java/io/ObjectInputStream.goToEndOfBlockData
> at java/io/ObjectInputStream.readNewObject
> at java/io/ObjectInputStream.readObject
> at com/ms/!!!Internal_Class_0.DefaultReadMethod
> at java/io/ObjectInputStream.invokeDefaultReadObject
> at java/io/ObjectInputStream.defaultReadObject
> at java/io/ObjectInputStream.readNewObject
> at java/io/ObjectInputStream.readObject
> at MainVirtual.run
> at java/lang/Thread.run
>
> What should i do now?


The process that did ObjectInputStream.readObject() doesn't have
access to a class definition that corresponds to the received object.
For example, you can't send an object "foo" of class MyClass to the
server, unless the server knows what MyClass is.

If the server doesn't need to actually *do* anything with the object
except immediately resend it on the ObjectOutputStream, let it read
the raw bytes from the SocketInputStream instead, and resend them on
the SocketOutputStream. That way it never has to create the object
itself.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
juicy
Guest
Posts: n/a
 
      09-23-2004
To gordon,
Yes, you are right. I finally know the main problem is because i try to
send a button event to server. I don't know why the server can read the
event which is sent by client but when it resend it on the
SocketOutputStream, the client can't read it back.
I try to change the object as string instead of a button event, it works
well. Is that i can't send event like this way? or..
Does anyone can help me??

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      09-23-2004
On Thu, 23 Sep 2004 10:33:56 -0400, juicy wrote:

> Yes, you are right. I finally know the main problem is because i try to
> send a button event to server. I don't know why the server can read the
> event which is sent by client


No, it cannot! Look at the stacktrace closely..

java.lang.ClassNotFoundException
at java/io/ObjectInputStream.loadClass0
.....
at java/io/ObjectInputStream.readObject

It throws the exception when it tries to *read*
the object it is given. Your server cannot even
read the object, Gordon has suggested one anser,
but I will suggest another.

In your server code, top line..

import java.awt.Event;

Your server does not need it till run time,
that is why your code compiles, but to recognize
an Event you are reading, the java.awt.Event
must be imported to the server code.

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      09-23-2004
Andrew Thompson wrote:
> In your server code, top line..
>
> import java.awt.Event;
>
> Your server does not need it till run time,
> that is why your code compiles, but to recognize
> an Event you are reading, the java.awt.Event
> must be imported to the server code.


That can't be right. Java's import is nothing but a compiler
directive to allow the use of classnames without prepending the
package. It *cannot* have any influence whatsoever on runtime
behaviour. In compiled code and in serialized objects, all
classes are referred by their fully qualified name.

The only thing he needs is java.awt.Event in the server's
classpath, which should be no problem since it has been part
of the API since 1.1.
 
Reply With Quote
 
juicy
Guest
Posts: n/a
 
      09-24-2004
Yes, i have imported java.awt.Event but the result is still same.
Is that really the server cannot read the event?
//at server
public void run() {
Object x = null;
try {
x = ois.readObject();
System.out.println("print out what is received: "+x);
oos.writeObject(x);
oos.flush();
ois.close();
oos.close();
client.close();
} catch(Exception e) {}

I print out what is received at server:
java.awt.Event[id=1001,x=30,y=1,target=java.awt.Button[button2,30,1,60x40,label=Write],arg=Write]
Is that mean server has already received the event?



 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      09-24-2004
On Thu, 23 Sep 2004 22:18:41 -0400, juicy wrote:
> Yes, i have imported java.awt.Event but the result is still same.
> Is that really the server cannot read the event?


Which process - client or server - gets the ClassNotFoundException
from readObject()? You weren't clear about that.

Do both processes use the same version of the JRE (and class
libraries)?

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      09-24-2004
On Fri, 24 Sep 2004 00:48:18 +0200, Michael Borgwardt wrote:

> Andrew Thompson wrote:

...
>> Your server does not need it till run time,
>> that is why your code compiles, but to recognize
>> an Event you are reading, the java.awt.Event
>> must be imported to the server code.

>
> That can't be right.


No. I started on a wrong concept then went
happily with it. Thanks for correcting me.

And, to the OP. Apologies for the 'noise'.

But.. I strongly suggest you make a minimized test
case of code (you can do probably do this in under
100 lines) that displays the problem.

Post it on the group.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
 
Reply With Quote
 
juicy
Guest
Posts: n/a
 
      09-24-2004
Sorry, is at client side gets the ClassNotFoundException
from readObject().

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problems with readObject and EOF Exception _kOws Java 1 08-20-2007 02:53 PM
Tuning the performance of ObjectInputStream.readObject() kannan123@gmail.com Java 1 01-07-2005 07:01 PM
Serialization: readObject() and self method calls? Jim Garrison Java 0 10-21-2003 06:01 PM
question on serialization and readObject() mitch gart Java 1 10-17-2003 11:34 PM
objectInputStream.readObject() does not work properly after certain period of inactivity. Serial # 19781010 Java 1 07-15-2003 10:20 PM



Advertisments