ProgressBar 的 Robolectric 问题
当 Robolectric 尝试为具有 ProgressBar 的活动调用 onCreate 时,我不断收到 RuntimeException。我已将问题定位到布局 xml 文件中的此块。一旦我删除它并重新运行测试,一切就正常了。
<ProgressBar android:id="@+android:id/progress_large"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible"/>
这是完整的堆栈跟踪:
java.lang.RuntimeException: java.lang.RuntimeException: 16842752 is already defined with name: id/progress_large can't also call it: attr/theme
at com.xtremelabs.robolectric.RobolectricTestRunner.createResourceLoader(RobolectricTestRunner.java:314)
at com.xtremelabs.robolectric.RobolectricTestRunner.setupApplicationState(RobolectricTestRunner.java:268)
at com.xtremelabs.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:219)
at com.xtremelabs.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:199)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
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.RuntimeException: 16842752 is already defined with name: id/progress_large can't also call it: attr/theme
at com.xtremelabs.robolectric.res.ResourceExtractor.addRClass(ResourceExtractor.java:37)
at com.xtremelabs.robolectric.res.ResourceExtractor.addSystemRClass(ResourceExtractor.java:18)
at com.xtremelabs.robolectric.res.ResourceLoader.<init>(ResourceLoader.java:59)
at com.xtremelabs.robolectric.RobolectricTestRunner.createResourceLoader(RobolectricTestRunner.java:311)
... 17 more
我正在使用 github head (1.0-RC2),因为我认为 ShadowProgressBar 会帮助我,但它似乎没有,但我可能没有正确使用它。
我还认为 id 或样式导致了问题,但在 XML 中删除它们并没有阻止异常。
任何帮助将不胜感激。
更新
我将进度条 xml 更改为:
<ProgressBar
android:id="@+id/circle_progress_bar"
style="@android:style/Widget.ProgressBar.Large.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible" />
并且它有效。
I keep getting a RuntimeException from Robolectric when it tries to invoke an onCreate for an activity that has a ProgressBar. I've localized the issue to this block in the layout xml file. As soon as I remove this and re-run the test, things work fine.
<ProgressBar android:id="@+android:id/progress_large"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible"/>
Here is the full stack trace:
java.lang.RuntimeException: java.lang.RuntimeException: 16842752 is already defined with name: id/progress_large can't also call it: attr/theme
at com.xtremelabs.robolectric.RobolectricTestRunner.createResourceLoader(RobolectricTestRunner.java:314)
at com.xtremelabs.robolectric.RobolectricTestRunner.setupApplicationState(RobolectricTestRunner.java:268)
at com.xtremelabs.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:219)
at com.xtremelabs.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:199)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
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.RuntimeException: 16842752 is already defined with name: id/progress_large can't also call it: attr/theme
at com.xtremelabs.robolectric.res.ResourceExtractor.addRClass(ResourceExtractor.java:37)
at com.xtremelabs.robolectric.res.ResourceExtractor.addSystemRClass(ResourceExtractor.java:18)
at com.xtremelabs.robolectric.res.ResourceLoader.<init>(ResourceLoader.java:59)
at com.xtremelabs.robolectric.RobolectricTestRunner.createResourceLoader(RobolectricTestRunner.java:311)
... 17 more
I'm working of the github head (1.0-RC2) because I thought the ShadowProgressBar would help me out but it doesn't seem to have, but I might not be using it correctly.
I also thought the id or the style were causing the issue but removing them in the XML didn't stop the Exception.
Any help would be appreciated.
UPDATE
I changed the progress bar xml to this:
<ProgressBar
android:id="@+id/circle_progress_bar"
style="@android:style/Widget.ProgressBar.Large.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible" />
And it worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改
将
android:id="@+android:id/progress_large"
为
android:id="@+id/progress_large"
change
android:id="@+android:id/progress_large"
to
android:id="@+id/progress_large"