1

我正在尝试在使用 google Volley 库的项目上运行 roboelectric,当我尝试使用简单的字符串检查运行测试项目时,我不断收到相同的错误

java.lang.RuntimeException: java.lang.ClassNotFoundException: com.android.volley.R
    at org.robolectric.AndroidManifest.getRClass(AndroidManifest.java:79)
    at org.robolectric.AndroidManifest.getResourcePath(AndroidManifest.java:233)
    at org.robolectric.AndroidManifest.getIncludedResourcePaths(AndroidManifest.java:238)
    at org.robolectric.AndroidManifest.getIncludedResourcePaths(AndroidManifest.java:240)
    at org.robolectric.RobolectricTestRunner.createAppResourceLoader(RobolectricTestRunner.java:422)
    at org.robolectric.RobolectricTestRunner.getAppResourceLoader(RobolectricTestRunner.java:411)
    at org.robolectric.RobolectricTestRunner.setupApplicationState(RobolectricTestRunner.java:188)
    at org.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:134)
    at org.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:92)
    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.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: com.android.volley.R
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.robolectric.AndroidManifest.getRClass(AndroidManifest.java:77)
    ... 22 more

我的项目使用 android target sdk 16。

谢谢。

4

2 回答 2

0

通过删除 volley 库并将 Volley.jar 文件从其 bin 文件夹复制到我的 Main 项目 libs 文件夹并将其添加到构建路径来解决此异常

于 2013-07-09T12:29:28.837 回答
0

太晚了,但是对于新手来说,这是与 volley 和 android studio 集成的一个错误,但如果你使用新版本它会自动解决它implementation 'com.android.volley:volley:1.1.1

于 2020-10-20T22:16:37.197 回答