ProgressBar 的 Robolectric 问题

发布于 2024-11-15 01:50:48 字数 3211 浏览 3 评论 0原文

当 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶茶白久 2024-11-22 01:50:49

更改

android:id="@+android:id/progress_large"

android:id="@+id/progress_large"

change

android:id="@+android:id/progress_large"

to

android:id="@+id/progress_large"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文