简体   繁体   English

为什么在ActionBarActivity上运行测试时会出现NoClassDefFoundError?

[英]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. 所以我使用的是Robotium,我的测试类正在扩展ActivityInstrumentationTestCase2类。 I have imported the v7 support library in my main project and also in the test project as libraries. 我已经在我的主项目中导入了v7支持库,并在测试项目中导入了库。

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 . 现在我不明白的是,当我更改测试中的类以扩展Activity时,测试类正在工作,但当我将其更改为ActionBarActivity它返回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>

Ensure you export the v7 support library referenced in test project. 确保导出测试项目中引用的v7支持库。

Right click on the test project, properties->java build path->order and export tab. 右键单击测试项目,properties-> java build path-> order和export选项卡。

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) 有关示例,请参阅此处“设置”部分下的步骤5: http//www.stevenmarkford.com/android-ui-testing-with-espresso-basics-tutorial/ (尽管这显示了如何导出espresso库相同适用于这种情况)

I think your library v7 app compat has an import problem. 我认为您的库v7 app compat存在导入问题。

Try this: 尝试这个:

  • Import support library as a project from "sdk/extras/android/support/v7/appcompat". "sdk/extras/android/support/v7/appcompat".导入支持库作为项目"sdk/extras/android/support/v7/appcompat".

  • Reference library in your project (for Eclipse, "Properties - Android - Add" ). 项目中的参考库(对于Eclipse, "Properties - Android - Add" )。

  • Build projects (for Eclipse, "Projects - Build All" ). 构建项目(对于Eclipse, "Projects - Build All" )。 Make sure, you have "android.support.v7.appcompat" in your main project gen folder. 确保您的主项目gen文件夹中有"android.support.v7.appcompat"

If it still doesn't solve your problem, restart eclipse and clean and rebuild project 如果它仍然无法解决您的问题,请重新启动eclipse并清理并重建项目

If the problem persists, remove the support library from you computer and redownload it and follow above mentioned steps. 如果问题仍然存在,请从您的计算机中删除支持库并重新下载并按照上述步骤操作。

This code in the build.gradle solved similar problem for me: build.gradle中的这段代码为我解决了类似的问题:

configurations {
    androidTestCompile.exclude group: 'com.android.support', module: 'support-v4'
}

More here . 更多这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在尝试运行我的应用程序时会收到 NoClassDefFoundError? - Why do I get a NoClassDefFoundError when trying to run my application? 使用Apache Commons VFS时,为什么我的applet中会出现NoClassDefFoundError? - Why do I get a NoClassDefFoundError in my applet, when using Apache Commons VFS? 当我在ScalaIDE中运行代码时,为什么会出现`java.lang.NoClassDefFoundError:scala / Function1`? - Why do I get `java.lang.NoClassDefFoundError: scala/Function1` when I run my code in ScalaIDE? 为什么在Java中会收到NoClassDefFoundError异常? - Why do I get a NoClassDefFoundError Exception in Java? 当我尝试保存测试计划时,为什么会出现 NoClassDefFound 错误? - Why do I get a NoClassDefFound error when I try to save my test plan? 在Heroku上运行我的应用程序时,为什么会出现启动超时错误(错误R10)? - Why do I get a Boot timeout error (Error R10) when running my app on Heroku? 使用 AdoptJDK11 运行我的胖 jar 时,我的外部依赖项出现 NoClassDefFoundError。 怎么了? - I get NoClassDefFoundError on my external dependency when running my fat jar using AdoptJDK11. What is wrong? 尝试运行Swing桌面应用程序时,为什么会收到HelpSetException-NoClassDefFoundError? - Why do I get a HelpSetException - NoClassDefFoundError when trying to run a Swing desktop application? 为什么会收到此异常java.lang.NoClassDefFoundError? - Why do I get this exception java.lang.NoClassDefFoundError? 为什么会出现NoClassDefFoundError:java / awt / Desktop? - Why do I get NoClassDefFoundError: java/awt/Desktop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM