首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Android上使用Rhino时出现的问题

在Android上使用Rhino时出现的问题
EN

Stack Overflow用户
提问于 2010-10-05 05:33:35
回答 2查看 9.4K关注 0票数 18

我正尝试在我的安卓Java应用程序中使用Mozilla Rhino来评估一些JavaScript。我使用的是Eclipse + ADT插件。

首先,我尝试简单地从Mozilla的网站下载Rhino .jar文件,并将其作为Eclipse中的库添加到项目中。Eclipse很好地识别了它,并编译了应用程序。然而,当运行它时,我在调用Context.evaluateReader()时得到一个异常(参见下面的堆栈跟踪)。

然后,我尝试将Rhino源代码作为单独的Android项目添加到Eclipse中,将其标记为库并在我的项目中引用它,这足以让Eclipse对其进行编译,但导致了相同的错误。

这是我得到的堆栈跟踪(java.lang.UnsupportedOperationException: can't load this type of class file)

Thread [<7> 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

我的代码中遇到异常的部分如下所示:

        Context cx = Context.enter();
        cx.setLanguageVersion(Context.VERSION_1_7);
        Scriptable scope = cx.initStandardObjects();
        try {
            Object result = cx.evaluateReader(scope, new InputStreamReader(data), /* <<< exception here */
                    filename, 0, null);
        } catch (IOException e) {
            // ...
        }

我还找到了this blog post,它包含类似的代码,并说它可以工作。作者说他使用了Android Scripting站点上的一个jar文件。我发现的唯一jar文件是在rhino_extras_r3.zip中。但是,它并不包含.class文件,而是一个classes.dex文件。当我将它作为一个库添加到Eclipse中时,它无法识别它包含的类,因此无法编译我的项目,因为缺少对Rhino类的引用。

任何关于如何让它工作的帮助都是非常感谢的!

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3859305

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档