当我在 robolectric 1.1 中运行测试时,在扩展布局文件时会发生以下错误:
java.lang.RuntimeException: Could not find layout layout/home_layout
at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:92)
at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:82)
at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:86)
有谁知道为什么会发生这个错误?据我所见,在 robolectric 1.1 版中,加载布局文件的方式没有改变,它搜索文件夹 layout/:
private ViewNode getViewNodeByLayoutName(String layoutName) {
if (layoutName.startsWith("layout/") && !qualifierSearchPath.isEmpty()) {
String rawLayoutName = layoutName.substring("layout/".length());
for (String location : qualifierSearchPath) {
ViewNode foundNode = viewNodesByLayoutName.get("layout-" + location + "/" + rawLayoutName);
if (foundNode != null) {
return foundNode;
}
}
}
return viewNodesByLayoutName.get(layoutName);
}
但是如果布局文件在另一个目录中(例如layout-normal-hdpi),就会出现这个错误..
有谁知道任何解决方案?