我使用Robolectric来测试扩展自定义视图的活动,但是从TypedArray获取值时,所有内容都返回null或空字符串。需要做些什么才能从类型数组中获得正确的值?Robolectric TypedArray getString()返回null或空字符串
1
A
回答
2
Robolectric不会重新实现整个Android标准库。
这里是到TypeArray暗影类的链接: https://github.com/pivotal/robolectric/blob/master/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTypedArray.java
它似乎缺少一些东西。您可以使用此功能来确认它确实缺少这些功能: http://pivotal.github.com/robolectric/javadoc/com/xtremelabs/robolectric/Robolectric.html#logMissingInvokedShadowMethods()
这就是说,有希望。最近发布了Robolectric 2.0 Alpha 1。虽然我还没有使用它,但它声称将需要更少的影子实现,因为它将直接使用Android实现。
0
尝试使用getStringArray()
代替。例如:
String[] myStringArray = Robolectric.getShadowApplication().getResources()
.getStringArray(R.array.MyStringArrayIdentifier)
相关问题
- 1. 返回null或空字符串
- 2. MySQL格式化字符串或返回空字符串NULL
- 3. GCM GetRegistrationId返回空字符串/ null
- 4. Clipboard.GetText返回null(空字符串)
- 5. 字符串赋值,空格返回null
- 6. 什么都要返回string.Split(“;”)如果字符串为null或空
- 7. 如何为PartialViewResult返回空字符串(或null)?
- 8. 为什么我的EditText返回null或空字符串?
- 9. 正则表达式返回null与返回空字符串
- 10. 的NSString:返回值或空字符串
- 11. Nodejs Javascript TypedArray缓冲字符串,并再次返回
- 12. 的parseObject的getString()返回null指针列
- 13. 空字符串+ null =“null”?
- 14. OpenFileDialog.FileName返回空字符串
- 15. Textbox.value返回空字符串
- 16. Edittext返回空字符串
- 17. p:inputTextarea返回空字符串
- 18. preg_replace()返回空字符串
- 19. jHtmlArea返回空字符串
- 20. md5返回空字符串
- 21. file_get_contents返回空字符串
- 22. get_FOO_display返回空字符串
- 23. RegEx返回空字符串
- 24. List.OrderBy返回空字符串
- 25. 返回空字符串
- 26. json_decode返回空字符串
- 27. WTSQuerySessionInformation返回空字符串
- 28. c_str()返回空字符串
- 29. ifstream返回空字符串?
- 30. document.body.style.zoom返回空字符串?