• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Integer cannot be cast to client

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking for some help on a Client Server program for class. I am stuck on an error that says "java.lang.Integer cannot be cast to client1.Client$Employee". Not for sure what this is and have spent several hours working on it and trying different things. Anyone have any ideas?

Server Code:



Client Code:




 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Wes,

That's a lot of code; it would sure help if you'd give us all the information the compiler is giving you -- i.e., the line number where the error occurs!

But in general terms, it looks like you're using serialization to send objects between a client and server process over a socket. I see Strings, Integers, and Employee objects being written, and I see places in the code where you're reading an object and expecting it to be an Integer, a String, or an Employee, at different points. In any case, the error just means -- and I think you probably know this -- that at one of the points where you're expecting an Integer, the object you're getting over the socket is actually an Employee. All I can tell you is that you need to go over the logic, carefully, and make sure you understand the conditions under which each kind of object can be transmitted; and make sure that the other end always has a way to know what's coming next.
 
Wes Traylor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get this error from the code when I try to use the FindListener:

java.lang.Integer cannot be cast to client1.Client$Employee

On the client side this is the part of the code I'm having trouble with.

Sorry for the long code, wanted to include everything so that someone could copy and paste to run.


 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The server logs some messages for every request it processes. When you run this, and have an error with the FIND command, do you see FIND-related messaages on the server? What do they say?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that when your Server first connects to a client, it sends an Integer as a handshake, and your Client never reads that Integer. So later, when you do a FIND, then read the input stream you get the Integer that has been sitting there in the buffer waiting to be taken.

You should read the integer immediately after making the connection to the Server:
 
reply
    Bookmark Topic Watch Topic
  • New Topic