Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从AndroidStudio 2.4迁移到3.0时的Robolectric NPE_Android_Robolectric_Android Studio 3.0 - Fatal编程技术网

从AndroidStudio 2.4迁移到3.0时的Robolectric NPE

从AndroidStudio 2.4迁移到3.0时的Robolectric NPE,android,robolectric,android-studio-3.0,Android,Robolectric,Android Studio 3.0,当从AndroidStudio 2.4迁移到3.0时,我们对Robolectric的大部分(可能全部)测试都失败了,出现了下面的奇怪错误。我们使用的是机器人分子3.2.2 java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunne

当从AndroidStudio 2.4迁移到3.0时,我们对Robolectric的大部分(可能全部)测试都失败了,出现了下面的奇怪错误。我们使用的是机器人分子3.2.2

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException

    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:332)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:259)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:41)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:199)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    at org.robolectric.res.ResourceParser.load(ResourceParser.java:57)
    at org.robolectric.res.ResourceTableFactory.newResourceTable(ResourceTableFactory.java:21)
    at org.robolectric.res.ResourceMerger.buildResourceTable(ResourceMerger.java:22)
    at org.robolectric.RobolectricTestRunner.getAppResourceTable(RobolectricTestRunner.java:499)
    at org.robolectric.RobolectricTestRunner.access$600(RobolectricTestRunner.java:41)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:327)
... 19 more
Caused by: java.lang.NullPointerException
    at org.robolectric.res.DocumentLoader.loadFile(DocumentLoader.java:39)
    at org.robolectric.res.DocumentLoader.load(DocumentLoader.java:30)
    at org.robolectric.res.ResourceParser.load(ResourceParser.java:21)
... 24 more
是不是对Android Studio 3.0的支持还没有为Robolectric做好准备

更新

崩溃发生在Robolectric
DocumentLoader
类上

private void loadFile(FsFile dir, XmlLoader[] xmlLoaders) {
 if (!dir.exists()) {
  throw new RuntimeException("no such directory " + dir);
 }

 for (FsFile file : dir.listFiles(ENDS_WITH_XML)) {
  loadResourceXmlFile(file, xmlLoaders);
 }
}
dir.listFiles(以XML结尾)
时,它返回Null。这就是它崩溃的原因。也许在最新的Android Studio上,资源没有生成XML

更新

找到此PR。这可能会解决此问题,如果为空,
dir
不是目录

更新


将问题报告给Robolectric

如果从控制台运行,它会失败吗?是的。同样的失败。也许不是安卓工作室的问题。。。更多原因在于新的gradle?另外,您使用的是AAPT2(3.0的一部分),那么Roboelectric也不兼容:在您的
gradle.properties
文件中设置
android.enableApt2=false
。不幸的是,这将导致我的从属库中出现其他错误,我的即时应用程序将停止工作。酷!那就自己回答吧!