wood burning stoves 2.0*
The moose likes Distributed Java and the fly likes Classcast Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Classcast Exception" Watch "Classcast Exception" New topic
Author

Classcast Exception

Stephen Black
Ranch Hand

Joined: Aug 13, 2009
Posts: 50

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

Joined: May 22, 2012
Posts: 866
    
    5

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

Joined: Aug 13, 2009
Posts: 50

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

Joined: May 22, 2012
Posts: 866
    
    5


This reminds me java.lang.reflect.Proxy.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Classcast Exception
 
Similar Threads
Writing to a file
RMS question
Someone pls explain these technologies...
Difficulty running RMI server, Red Hat 7.0
RMIServer is abstract and cannot be instantiated