Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classcast Exception

 
Stephen Black
Ranch Hand
Posts: 52
1
Chrome MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get this error when try to cast my RMI object back to what I consider to be it's proper type
java.lang.ClassCastException: $Proxy0 cannot be cast to GumballMonitorRMIClient.RMIAdaptor
It seems to me that I believe that the object is of type RMIAdaptorRemoteInterface with a concrete type of RMIAdaptor
but the computer thinks the object is of type $Proxy0, which is leading to a number of problems

So where did it go wrong?
I created the remote object like this

And now I want to access those methods remotely using this code

But when I try to cast it back to it's former type
the compilier argues with me about what type it reall is and gives me this error message
java.lang.ClassCastException: $Proxy0 cannot be cast to GumballMonitorRMIClient.RMIAdaptor
 
Ivan Jozsef Balazs
Rancher
Posts: 979
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the compilier argues with me about what type it reall is and gives me this error message
java.lang.ClassCastException: $Proxy0 cannot be cast to GumballMonitorRMIClient.RMIAdapto


A sidenote: java.lang.ClassCastException is a runtime exception, it does not come from the compiler.
 
Stephen Black
Ranch Hand
Posts: 52
1
Chrome MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help but after learning that many believe RMI to be an outdated technology,
I am actually beyond caring
 
Ivan Jozsef Balazs
Rancher
Posts: 979
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This reminds me java.lang.reflect.Proxy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic