This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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: 867
    
    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: 867
    
    5


This reminds me java.lang.reflect.Proxy.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Classcast Exception