Reputation: 31
I was writing a RMI application. I have a method on the server side, which returns an ArrayList<User>
and User
is a class I defined myself. The code is like: list = obj.getList(); System.out.println(list.get(0).getName());
, and this line generated an exception of "com.sun.proxy.$Proxy0 cannot be cast to User". Can anybody help me about that?
Upvotes: 0
Views: 12815
Reputation:
I remember I had this problem before.
I added extends Remote
at the end of public interface nameOfYourInterface
. It worked for me.
Upvotes: 0
Reputation: 310840
If User
is an exported remote object, as it seems to be, it appears in the client as the remote interface it implements, not as the implementation class.
So that's what you must cast it to. In this case that means declaring your List as List<UserInterface>
, where UserInterface
is the name of the remote interface. Adjust to suit.
Upvotes: 3