JCL
JCL copied to clipboard
Android suporte
Do not know if that library should work on android, but the test did not get good results.
package com.example.JavaDN;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import org.xeustechnologies.jcl.JarClassLoader;
import org.xeustechnologies.jcl.JclObjectFactory;
import java.net.MalformedURLException;
import java.net.URL;
public class MainActivity extends Activity implements Runnable {
JarClassLoader mJcl;
TextView log;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mJcl = new JarClassLoader();
log = (TextView) findViewById(R.id.log);
new Thread(this).start();
}
@Override
public void run() {
log.setText("Loading lib...");
try {
mJcl.add(new URL("https://dl.dropboxusercontent.com/u/67269258/lib_class.jar"));
} catch (MalformedURLException e){
e.printStackTrace();
}
JclObjectFactory factory = JclObjectFactory.getInstance();
//Create object of loaded class
Object obj = factory.create(mJcl, "Math");
log.setText("ready! " + obj);
}
}
Error:
06-08 19:17:15.799 7604-7617/com.example.JavaDN E/dalvikvm﹕ ERROR: defineClass(0x4261d390, Math, 0x42691238, 0, 812)
06-08 19:17:15.799 7604-7617/com.example.JavaDN W/dalvikvm﹕ threadid=11: thread exiting with uncaught exception (group=0x41bef700)
06-08 19:17:15.804 7604-7617/com.example.JavaDN E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-3011
org.xeustechnologies.jcl.exception.JclException: java.lang.UnsupportedOperationException: can't load this type of class file
at org.xeustechnologies.jcl.JclObjectFactory.create(JclObjectFactory.java:102)
at org.xeustechnologies.jcl.JclObjectFactory.create(JclObjectFactory.java:85)
at com.example.JavaDN.MainActivity.run(MainActivity.java:44)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
at java.lang.VMClassLoader.defineClass(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:292)
at java.lang.ClassLoader.defineClass(ClassLoader.java:256)
at org.xeustechnologies.jcl.JarClassLoader.access$000(JarClassLoader.java:50)
at org.xeustechnologies.jcl.JarClassLoader$LocalLoader.loadClass(JarClassLoader.java:254)
at org.xeustechnologies.jcl.AbstractClassLoader.loadClass(AbstractClassLoader.java:122)
at org.xeustechnologies.jcl.AbstractClassLoader.loadClass(AbstractClassLoader.java:95)
at org.xeustechnologies.jcl.JclObjectFactory.create(JclObjectFactory.java:100)
at org.xeustechnologies.jcl.JclObjectFactory.create(JclObjectFactory.java:85)
at com.example.JavaDN.MainActivity.run(MainActivity.java:44)
at java.lang.Thread.run(Thread.java:841)
Works on pc:
package com.example.JavaDN;
import org.xeustechnologies.jcl.JarClassLoader;
import org.xeustechnologies.jcl.JclObjectFactory;
import java.net.MalformedURLException;
import java.net.URL;
/**
* Main
*/
public class Main {
public static void main(String[] args){
JarClassLoader mJcl = new JarClassLoader();
System.out.println("Loading lib...");
try {
mJcl.add(new URL("https://dl.dropboxusercontent.com/u/67269258/lib_class.jar"));
} catch (MalformedURLException e){
e.printStackTrace();
}
JclObjectFactory factory = JclObjectFactory.getInstance();
//Create object of loaded class
Object obj = factory.create(mJcl, "Math");
System.out.println("ready! " + obj);
}
}
I believe that the solution to this lies in the proxy (ProxyClassLoader)
http://larshamren.blogspot.com.br/2012/02/android-dynamically-loading-classes.html
The problem is to implement it.