This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

writeObject / readObject question  RSS feed

 
jeff willis
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a client/server application that I've implemented using JAVA sockets.

I am getting a "class not found" exception from the server when it tries to readObject().

Here is my client set up:


And my server set up (exception occurs at the readObject() line)


Notice the "myClass" is the class of the object I want to send and receive.


Am I getting this exception because the two "myClass" classes are actually two different sub-classes?

To save time during implementation, I simply copied and pasted the myClass class into both the server and the client classes.
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jw wvu:

. . .the two "myClass" classes are actually two different sub-classes?


Nope. Your two myClass classes are different inner classes. If you look at the class files generated by the compiler, one will be named client$myClass and the other is server$myClass. They are unique classes which do not inherit any properties from their enclosing class. An inner class can only be accessed within the scope it is declared. For example, client$myClass can only be accessed within the client class.
A subclass is a relationship created with the "extends" keyword. A subclass inherits all the accessible members and methods of it's superclass. For example, java.lang.Integer is declared as:

so we say that Integer is a subclass of Number.
You should create a unique class called myClass and place it in both the client and server's classpath.
 
jeff willis
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, it looks like I'm going to have to do that.

crap. I was hoping that the copy/paste of "myCLass" would save me some time but I guess not.

Thanks for your help.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!