6

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.

Line 14 of the Helper Class is:

this.httpHelper = new HttpHelper(userProfile);

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.

Janusz
  • 187,060
  • 113
  • 301
  • 369
  • What's at line 14 of Helper.java? – RickNotFred Mar 12 '10 at 14:49
  • Are you using external libraries in your project ? If this is the case the instruction on this [article](http://dtmilano.blogspot.com/2009/12/android-testing-external-libraries.html) may help you. – Diego Torres Milano Mar 12 '10 at 18:12
  • hi, I did as the article says but it still have error. At first, I added external Java project to "Project" tab, then I checked it on "Order and Export" tab. It still has that error. "cross-loader access.." on the line using external project. (In fact, the external project is on same workspace) – emeraldhieu Aug 02 '11 at 16:38
  • I haven't seen this problem either including external jars or other java project from the workspace. – Diego Torres Milano Aug 03 '11 at 03:37
  • This didn't fix my error at all – JPM Feb 16 '12 at 22:05

1 Answers1

4

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

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.

David Momenso
  • 1,931
  • 1
  • 12
  • 10