为什么我的运行Android的测试时,我得到一个非法访问错误? [英] Why do I get a Illegal Access Error when running my Android tests?

查看:210
本文介绍了为什么我的运行Android的测试时,我得到一个非法访问错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行我在模拟器Android的测试时,我得到了下面的堆栈跟踪:

I get the following stack trace when running my Android tests on the Emulator:

java.lang.NoClassDefFoundError: client.HttpHelper
at client.Helper.<init>(Helper.java:14)  
at test.Tests.setUp(Tests.java:15)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:164)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:151)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:425)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1520)
Caused by: java.lang.IllegalAccessError: cross-loader access from pre-verified class
at dalvik.system.DexFile.defineClass(Native Method)
at dalvik.system.DexFile.loadClass(DexFile.java:193)  
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:203)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
... 11 more

我跑我从一个额外的项目测试。它似乎有一些问题与其他项目加载的类。我已经运行前的测试,但现在他们都失败了。根据测试项目运行没有任何问题。

I run my tests from an extra project. And it seems there are some problems with loading the classes from the other project. I have run the tests before but now they are failing. The project under tests runs without problems.

助手类的第14行是:

this.httpHelper = new HttpHelper(userProfile);

我开始HttpHelper类,负责执行httpqueries。我认为,这在某种程度上辅助类已不存在,但我不知道为什么。

I start a HttpHelper class that is responsible for executing httpqueries. I think somehow this helper class is not available anymore, but I have no clue why.

推荐答案

我有同样的问题,但对我来说,我添加库引用到应用程序和测试项目。

I was having the same problem but in my case I was adding the library reference to both the application and test projects.

通过消除测试项目的参考图书馆,只留下了参考应用程序项目的问题得到解决。该java.lang.IllegalAccessError异常和消息一类以意想不到的DEX解决为线索,以帮助解决这个问题。

By removing the reference to library from the test project and leaving only the reference to the application project the problem was solved. The java.lang.IllegalAccessError exception and the message 'Class resolved by unexpected DEX' were the clues to help solve this problem.

这篇关于为什么我的运行Android的测试时,我得到一个非法访问错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆