Jas On Jas On - 1 month ago 5
Java Question

Java RMI - Passing Objects

I'm running a Java program on a

Raspberry Pi
and an
on a smartphone. The app should be able to invoke methods running on the
does not include the standard Java RMI package, I used
: http://lipermi.sourceforge.net/

So far so good,
does work well for passing primitive data types such as boolean or int.

What I want to do now is passing an
from the Server to the app but every time I run the method, I receive following error:

LipeRMIException:Class java.util.ArrayList is not assignable from control.ServerInt
at lipermi.handler.CallHandler.exportObject(CallHandler.java:54)
at lipermi.handler.CallHandler.exportObject(CallHandler.java:48)
at control.RMIServer.createServer(RMIServer.java:26)
at control.Main.main(Main.java:17)

I do not understand what I'm doing wrong here.


public class RMIServer implements ServerInt{
private static final long serialVersionUID = 1L;
private ArrayList<String> list;

public RMIServer() {
list = new ArrayList<String>();


public void createServer() {
try {
CallHandler callHandler = new CallHandler();
callHandler.registerGlobal(ServerInt.class, this);
callHandler.exportObject(ServerInt.class, list);
Server server = new Server();
server.bind(7777, callHandler);

server.addServerListener(new IServerListener() {

public void clientDisconnected(Socket socket) {}

public void clientConnected(Socket socket) {}

} catch (LipeRMIException | IOException e) {

public ArrayList<String> getPWMLines() {
return list;


import java.util.ArrayList;

public interface ServerInt{
public ArrayList<String> getPWMLines();


You obviously misuse the method CallHandler#exportObject(Class, Object) the first parameter must be a class representing an interface and the second parameter must be an instance of a class that implements this interface. Here you provide an ArrayList as second parameter which is clearly not an instance of ServerInt that is why you get this exception.

Here is a good example of how to use this method:

MyRemoteListener listenerImplementation = new MyRemoteListenerImpl();
callHandler.exportObject(MyRemoteListener.class, listenerImplementation);

In this case the first parameter is the interface MyRemoteListener and the second is an instance of MyRemoteListenerImpl which is an implementation of the interface MyRemoteListener.

To expose your List you can try callHandler.registerGlobal(List.class, list)