gpt4 book ai didi

android - Robolectric : NotFoundException: unknown resource 0 at org. robolectric.shadows.ShadowAssetManager.getAndResolve (ShadowAssetManager.java:258)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:46:14 33 4
gpt4 key购买 nike

我在测试 getView 时遇到错误。测试代码在测试用例期间调用 View.setImageResource(0) 以在异常发生时设置空图像。

我用 Eclipse 运行了测试 robolectric-2.2-20130712.161723-17-jar-with-dependencies.jar。我尝试用 ShadowResources.createFor(new ResourceLoader() {...} 替换 ResouceLoader。但它不起作用。我替换的 ResouceLoader 没有被调用。

有人知道怎么解决吗?

android.content.res.Resources$NotFoundException: unknown resource 0
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:258)
at org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:85)
at android.content.res.AssetManager.getResourceValue(AssetManager.java)
at android.content.res.Resources.getValue(Resources.java:1009)
at android.content.res.Resources.getDrawable(Resources.java:658)
at org.robolectric.shadows.ShadowView.buildDrawable(ShadowView.java:92)
at org.robolectric.shadows.ShadowImageView.setImageResource(ShadowImageView.java:38)
at android.widget.ImageView.setImageResource(ImageView.java)
at com.mobile.client.share.edentity.PhotostreamAdapter.getView(PhotostreamAdapter.java:54)
at com.mobile.client.share.edentity.PhotostreamAdapterTest.testGetView(PhotostreamAdapterTest.java:163)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
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)

我的 Apdater ContentDetailsAdapter 机器人单元测试中的另一个类似问题来自语句 mContext.getResources().getString(R.string.delete_hint_title)。 mContext 由 Robolectric.getShadowApplication().getApplicationContext() 创建。我关于 Roboletric 的配置有问题吗?我能够在我的单元测试中调用 ProgressDialog.show(mContext, "", "") 。看来问题总是出在资源上。这是堆栈:

android.content.res.Resources$NotFoundException: String resource ID #0x7f07004f
at android.content.res.Resources.getText(Resources.java:229)
at android.content.res.Resources.getString(Resources.java:313)
at com.mobile.client.share.edentity.ContentDetailsAdapter.checkDeletedSelection(ContentDetailsAdapter.java:220)
at com.mobile.client.share.edentity.ContentDetailsAdapter.getCheckedItems(ContentDetailsAdapter.java:178)
at com.mobile.client.share.edentity.SetsAdapterTest.testGetCheckedItems(SetsAdapterTest.java:361)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
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)

最佳答案

我遇到了与您的第二期类似的错误。我的环境是根据 http://www.youtube.com/watch?v=3mjcg5gfDLE 设置的

提供的示例适用于我的 Eclipse,但是当我尝试将 MyProjectTest 链接到我自己的应用程序时,出现了您描述的第二个错误。

视频在 6:00 描述了解决方案。

MyProjectTest -> Run As Configuration -> JUnit -> MyProjectTestConfiguration -> Arguments -> 单击“Other”单选按钮 -> Workspace -> 选择

要点是:如果您为不同的应用程序运行 robolectric 测试,则必须将“工作目录”指向它。此外,您需要将您的测试文件夹从 MyProjectTest 链接到 .

关于android - Robolectric : NotFoundException: unknown resource 0 at org. robolectric.shadows.ShadowAssetManager.getAndResolve (ShadowAssetManager.java:258),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19043713/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com