android Rhino错误无法加载此类文件 [英] android Rhino error can't load this type of class file
问题描述
我在android中使用Rhino在Android(java)中执行JavaScript函数代码并从此代码中获取结果,但是我遇到了此异常
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):由以下原因引起:java.lang.UnsupportedOperationException:无法加载这种类型的类文件
01-22 11:33:57.063: E/AndroidRuntime(29175): Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
这是我的代码
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();
}
我在方法上遇到了异常
Function fct = context.compileFunction(scope,test,"script",1,null);
Function fct = context.compileFunction(scope, test, "script", 1, null);
加载Web视图后,我在onCreate()方法中编写了这段代码,并使用rhino1_7R2.jar作为Rhino的jar.
I wrote this code in method onCreate() after load the webview and I use rhino1_7R2.jar as a jar for Rhino.
请帮助我,如果您知道通过Android中的JavaScript(函数的返回值)获取值的任何其他方法,请提出建议.
Please help me and if u know any other way to get a value from JavaScript(return value of function) in android please advice.
谢谢
推荐答案
I had the same problem and I have found a solution here: Problems using Rhino on Android
默认情况下,rhino将尝试通过动态生成JVM字节码来进行优化. Android不会通过Dalvik字节码运行JVM字节码.这就是为什么您必须禁用优化的原因:
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);
最诚挚的问候
这篇关于android Rhino错误无法加载此类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!