[英]Resources$NotFoundException for String array with Robolectric
In my Robolectric tests when calling getResources().getStringArray(R.array.some_array_id)
I get a crash with Resources$NotFoundException
. 在我的Robolectric测试中,当调用getResources().getStringArray(R.array.some_array_id)
, Resources$NotFoundException
导致崩溃。
This does not happen with other resource types, and it works in my app when running outside of tests. 其他资源类型则不会发生这种情况,并且在测试以外运行时可以在我的应用程序中运行。
The problem was how I had defined the array in resources, I used: 问题是我如何使用资源定义数组:
<array name="some_array_id">
</array>
I needed to use: 我需要使用:
<string-array name="some_array_id">
</string-array>
Either one works fine with the real Android SDK but only string-array
works with Robolectric. 哪一种都可以在真正的Android SDK上正常运行,但是只有string-array
可以与Robolectric一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.