与ProgressBar的Robolectric问题

时间:2011-06-10 06:44:55

标签: android progress-bar robolectric

当Robolectric尝试为具有ProgressBar的活动调用onCreate时,我不断从Robolectric获取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头(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" />

它有效。

1 个答案:

答案 0 :(得分:1)

更改

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

android:id="@+id/progress_large"