• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

writeObject / readObject question

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic