Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems using Rhino on Android
    primarykey
    data
    text
    <p>I'm trying to use <a href="http://www.mozilla.org/rhino/" rel="noreferrer">Mozilla Rhino</a> in my Java application for Android to evaluate some JavaScript. I am using Eclipse + ADT plugin.</p> <p>First I tried simply downloading the Rhino .jar file from Mozilla's website and adding it to the project as a library in Eclipse. Eclipse recognised it fine and compiled the application. However, when running it I get an exception when calling <code>Context.evaluateReader()</code> (see below for stack trace).</p> <p>Then I tried adding the Rhino source code as a separate Android project in Eclipse, marking it as a library and referencing it in my project, which was enough to get Eclipse to get it to compile, but led to the same error.</p> <p>This is the stacktrace I get (<code>java.lang.UnsupportedOperationException: can't load this type of class file</code>)</p> <pre><code>Thread [&lt;7&gt; Thread-8] (Suspended (exception UnsupportedOperationException)) DefiningClassLoader(ClassLoader).defineClass(String, byte[], int, int, ProtectionDomain) line: 338 DefiningClassLoader.defineClass(String, byte[]) line: 62 Codegen.defineClass(Object, Object) line: 159 Codegen.createScriptObject(Object, Object) line: 114 Context.compileImpl(Scriptable, Reader, String, String, int, Object, boolean, Evaluator, ErrorReporter) line: 2440 Context.compileReader(Reader, String, int, Object) line: 1326 Context.compileReader(Scriptable, Reader, String, int, Object) line: 1298 Context.evaluateReader(Scriptable, Reader, String, int, Object) line: 1137 TimetableProcessor.evaluate(InputStream, String, String[]) line: 31 TimetableProcessor.processBasicData(InputStream, String) line: 58 TimetableProcessor.process(InputStream, String) line: 52 TimetableUpdater.update() line: 53 Main$1$1.run() line: 22 </code></pre> <p>The bit of my code that hits the exception looks like this:</p> <pre><code> Context cx = Context.enter(); cx.setLanguageVersion(Context.VERSION_1_7); Scriptable scope = cx.initStandardObjects(); try { Object result = cx.evaluateReader(scope, new InputStreamReader(data), /* &lt;&lt;&lt; exception here */ filename, 0, null); } catch (IOException e) { // ... } </code></pre> <p>I also found <a href="http://divineprogrammer.blogspot.com/2009/11/javascript-rhino-on-android.html" rel="noreferrer">this blog post</a> which contains similar code and says it works. The author says he used a jar file from the <a href="http://code.google.com/p/android-scripting/" rel="noreferrer">Android Scripting</a> site. The only jar file I found there was in <code>rhino_extras_r3.zip</code>. However, it doesn't contain <code>.class</code> files but rather a <code>classes.dex</code> file. When I added this as a library in Eclipse, it didn't recognise the classes it contains and thus failed to compile my project because of the missing references to Rhino classes.</p> <p>Any help at all on how to get this to work is appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload