android Rhino error can't load this type of class file

北战南征 提交于 2019-12-04 11:35:20

问题


I'm using Rhino in android to execute JavaScript function code in Android(java) and get the result from this code, but I got this exception

01-22 11:33:57.063: E/AndroidRuntime(29175): Caused by: java.lang.UnsupportedOperationException: can't load this type of class file

This is my code

String test = "function abc(x,y) {return x+y;}";
    org.mozilla.javascript.Context context = org.mozilla.javascript.Context.enter();
    try {
        ScriptableObject scope = context.initStandardObjects();
        Scriptable that = context.newObject(scope);
        Function fct = context.compileFunction(scope, test, "script", 1, null);
        Object result = fct.call(context, scope, that, new Object[] { 2, 3 });
        Log.i("JML...Info", "jajajajaj = " + org.mozilla.javascript.Context.jsToJava(result, int.class));
    } finally {
        org.mozilla.javascript.Context.exit();
    }

I got the exception on method

Function fct = context.compileFunction(scope, test, "script", 1, null);

I wrote this code in method onCreate() after load the webview and I use rhino1_7R2.jar as a jar for Rhino.

Please help me and if u know any other way to get a value from JavaScript(return value of function) in android please advice.

Thanks


回答1:


I had the same problem and I have found a solution here: Problems using Rhino on Android

By default, rhino will try do optimization by generating JVM bytecode on the fly. Android doesn't run JVM bytecode byt Dalvik bytecode. That is why you have to disable optimization:

context.setOptimizationLevel(-1);

Best regards



来源:https://stackoverflow.com/questions/14454686/android-rhino-error-cant-load-this-type-of-class-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!