Very new to java rmi. I am trying to create a stub of my server object with the lines:
SorterServer obj = new SorterServer();
Sorter stub = (Sorter) UnicastRemoteObject.exportObject((Remote) obj, 0);
however, casting 'obj' to Remote throws the error
java.lang.ClassCastException: class SorterServer cannot be cast to class java.rmi.Remote (SorterServer is in unnamed module of loader 'app'; java.rmi.Remote is in module java.rmi of loader 'bootstrap')
UnicastRemoteObject is the only way I know of creating a stub, and it requires the object to be cast to a Remote. This exact line of code worked in a tutorial I was following, so I am not sure why it produces this error here. I have done some research on this error, and loaders, but didn't really find anything specific to me. Sorry if this is extremely obvious, as I have not done this stuff before.
Is SorterServer your class? Does it implement Remote?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.