Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get a NoClassDefFoundError when running my test on an ActionBarActivity?

So I am using Robotium and my test class is extending the ActivityInstrumentationTestCase2 class. I have imported the v7 support library in my main project and also in the test project as libraries.

Now what I don't understand is that the test class is working when I change the class under test to extend Activity but when I change it to ActionBarActivity it returns a NoClassDefFoundError.

Am I missing anything?

Here is the Log I am getting

04-11 21:32:16.551: E/dalvikvm(23925): Could not find class 'com.example.project.ActivityClass', referenced from method com.example.project.tests.ActivityClass.<init>
like image 275
John Ernest Guadalupe Avatar asked Apr 09 '15 10:04

John Ernest Guadalupe


2 Answers

Ensure you export the v7 support library referenced in test project.

Right click on the test project, properties->java build path->order and export tab.

For an example see step 5 under "Setup" Section here: http://www.stevenmarkford.com/android-ui-testing-with-espresso-basics-tutorial/ (although this is showing how to export the espresso library the same would apply in this case)

like image 161
Steven Mark Ford Avatar answered Nov 14 '22 22:11

Steven Mark Ford


I think your library v7 app compat has an import problem.

Try this:

  • Import support library as a project from "sdk/extras/android/support/v7/appcompat".

  • Reference library in your project (for Eclipse, "Properties - Android - Add").

  • Build projects (for Eclipse, "Projects - Build All"). Make sure, you have "android.support.v7.appcompat"in your main project gen folder.

If it still doesn't solve your problem, restart eclipse and clean and rebuild project

If the problem persists, remove the support library from you computer and redownload it and follow above mentioned steps.

like image 20
Maxouille Avatar answered Nov 15 '22 00:11

Maxouille