java.lang.ClassNotFoundException:android.R
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java.lang.ClassNotFoundException:android.R,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2923字,纯文字阅读大概需要5分钟。
内容图文
![java.lang.ClassNotFoundException:android.R](/upload/InfoBanner/zyjiaocheng/824/37cb0c5b3a884d7a90799451c61ecb5a.jpg)
我正在尝试使用Robolectric 2.2运行一个简单的junit测试,但我得到以下使用ADT包22错误:
java.lang.NoClassDefFoundError: android/R
at org.robolectric.bytecode.Setup.<clinit>(Setup.java:40)
at org.robolectric.RobolectricTestRunner.createSetup(RobolectricTestRunner.java:137)
at org.robolectric.RobolectricTestRunner.createSdkEnvironment(RobolectricTestRunner.java:115)
at org.robolectric.RobolectricTestRunner$3.create(RobolectricTestRunner.java:278)
at org.robolectric.EnvHolder.getSdkEnvironment(EnvHolder.java:21)
at org.robolectric.RobolectricTestRunner.getEnvironment(RobolectricTestRunner.java:276)
at org.robolectric.RobolectricTestRunner.access$100(RobolectricTestRunner.java:57)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:190)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: android.R
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 24 more
代码给出了我的错误如下:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import com.mycomp.myapp.R;
@RunWith(RobolectricTestRunner.class)
public class ListToWatchActivityTest {
@Test
public void shouldHaveApplicationName() throws Exception {
String appName = new ListToWatchActivity().getResources().getString(R.string.app_name);
assertThat(appName, equalTo("MyApp"));
}
}
有人可以帮助我理解为什么我会收到此错误?
谢谢.
解决方法:
将android.jar库添加到类路径中.
内容总结
以上是互联网集市为您收集整理的java.lang.ClassNotFoundException:android.R全部内容,希望文章能够帮你解决java.lang.ClassNotFoundException:android.R所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。