简体   繁体   English

com.sun.proxy.$proxy0 无法转换为 XXX

[英]com.sun.proxy.$proxy0 cannot be cast to XXX

I was writing a RMI application.我正在编写一个 RMI 应用程序。 I have a method on the server side, which returns an ArrayList<User> and User is a class I defined myself.我在服务器端有一个方法,它返回一个ArrayList<User>并且User是我自己定义的 class。 The code is like: list = obj.getList(); System.out.println(list.get(0).getName());代码如下: list = obj.getList(); System.out.println(list.get(0).getName()); 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". ,并且此行生成“com.sun.proxy.$Proxy0 无法转换为用户”的异常。 Can anybody help me about that?有人可以帮我吗?

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. 如果User是一个导出的远程对象(看起来如此),则它在客户端中显示为它实现的远程接口,而不是实现类。

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. 在这种情况下,这意味着将您的列表声明为List<UserInterface> ,其中UserInterface是远程接口的名称。 Adjust to suit. 调整以适合。

I remember I had this problem before.我记得我以前遇到过这个问题。 I added extends Remote at the end of public interface nameOfYourInterface .我在public interface nameOfYourInterface的末尾添加了extends Remote It worked for me.它对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.sun.proxy。$ Proxy0无法转换为 - com.sun.proxy.$Proxy0 cannot be cast to 线程“main”中的异常 java.lang.ClassCastException:类 com.sun.proxy.$Proxy0 不能转换为类船员 - Exception in thread “main” java.lang.ClassCastException: class com.sun.proxy.$Proxy0 cannot be cast to class crewcut java.lang.ClassCastException: com.sun.proxy.$Proxy0 不能转换为 org.andrea.myexample.myDeclarativeTransactionSpring.StudentJDBCTemplate - java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to org.andrea.myexample.myDeclarativeTransactionSpring.StudentJDBCTemplate java:java.lang.ClassCastException:com.sun.proxy.$Proxy0 类无法转换为 com.sun.tools.javac.processing.JavacProcessingEnvironment 类 - java: java.lang.ClassCastException: class com.sun.proxy.$Proxy0 cannot be cast to class com.sun.tools.javac.processing.JavacProcessingEnvironment com.sun.proxy。$ Proxy1无法转换为 - com.sun.proxy.$Proxy1 cannot be cast to com.sun.proxy.$Proxy439 无法强制转换为 DDLRecordSetLocalService - com.sun.proxy.$Proxy439 cannot be cast to DDLRecordSetLocalService ClassCastException:com.sun.proxy.$ProxyX 无法转换为类 - ClassCastException: com.sun.proxy.$ProxyX cannot be cast to a class ComboPooledDataSource -com.sun.proxy。$ Proxy78无法转换为oracle.sql.CLOB - ComboPooledDataSource -com.sun.proxy.$Proxy78 cannot be cast to oracle.sql.CLOB java.lang.ClassCastException:com.sun.proxy。$ Proxy47无法转换为 - java.lang.ClassCastException: com.sun.proxy.$Proxy47 cannot be cast to RMI:java.lang.ClassCastException:com.sun.proxy。$ Proxy1无法转换为Funktion - RMI: java.lang.ClassCastException: com.sun.proxy.$Proxy1 cannot be cast to Funktion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM