Skip to main content

phoneME - library already loaded in another classloader.

No replies
markbr
Offline
Joined: 2008-03-10

I have an XletManager and two apps (Xlet) that use an common class IXCRegistry that loads an native library by JNI. I'm getting the already loaded in another classloader exception. I think that the problem is that since Xlets are loaded in different classLoader they dont see the class due to the reduced view of their context. Is that right? If yes, is there an way to do a workaround on this situation?

Code below: (Removed the imports to make it clear)

Error Message

java.lang.UnsatisfiedLinkError: Native Library /home/marcosroriz/workspace/UFG-InterAPPJava/dist/libInterAppCC.so already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibraryInternal(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at IxcRegistry.(Unknown Source)
at java.lang.Class.runStaticInitializers(Unknown Source)
at Client.startXlet(Unknown Source)
at com.sun.xlet.XletManager.handleRequest(Unknown Source)
at com.sun.xlet.XletStateQueue.dispatchRequests(Unknown Source)
at com.sun.xlet.XletStateQueue$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at java.lang.Thread.startup(Unknown Source)

IxcRegistry.java

public final class IxcRegistry {

// This call will try to load the native library that contains the code of
// the IxcRegistry
static {
System.out.println("Trying to LOAD LIB");
System.loadLibrary("InterAppCC");
System.out.println("Finish Load Lib");
}

// Private constructor to assume there is only one IxcRegistry
private IxcRegistry() {}

public native void bind(String name, Remote obj) throws StubException,
AlreadyBoundException;

public native static IxcRegistry getRegistry(XletContext context);

public native String[] list();

public native Remote lookup(String name) throws StubException,
NotBoundException;

public native void rebind(String name, Remote obj) throws StubException,
AccessException;

public native void unbind(String name) throws NotBoundException,
AccessException;

public native void unbindAll();

}

Client.java

public class Client implements Xlet {

private XletContext context;

public void initXlet(XletContext ctx) throws XletStateChangeException {
context = ctx;
System.out.println("INIT XLET");
}

public void startXlet() throws XletStateChangeException {
try {
IxcRegistry registry = IxcRegistry.getRegistry(context);
Server rect = (Server) registry.lookup("Server");
System.out.println("Result: " + rect.speedCalcule(300, 2));
} catch (Exception ex) {
ex.printStackTrace();
}
}

public void pauseXlet() {
System.out.println("PAUSE XLET");
}

public void destroyXlet(boolean unconditional)
throws XletStateChangeException {
System.out.println("DESTROY XLET");
}

}

Server.java

public class ServerImpl implements Xlet, Server {

private XletContext context;

public void initXlet(XletContext ctx) throws XletStateChangeException {
context = ctx;
System.out.println("INIT SERVER XLET");
}

public void startXlet() throws XletStateChangeException {
System.out.println("START SERVER XLET");

System.out.println("------ Bind Started on Java");
try {
IxcRegistry reg = IxcRegistry.getRegistry(context);
reg.bind("Server", this);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("------ Bind Finished on Java");
}

public void pauseXlet() {
System.out.println("PAUSE SERVER XLET");
}

public void destroyXlet(boolean unconditional)
throws XletStateChangeException {
System.out.println("DESTROY SERVER XLET");
}

public double speedCalcule(int distance, int time) {
double speed = distance / time;
return speed;
}
}

Thanks in advance,
Marcos

Message was edited by: markbr

Message was edited by: markbr