热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

NopackageIDfoundResources$NotFoundExceptionStringnotfound

DescriptionHello.IconstructedasimpleJUnittestwhichtriestogetast


Description

Hello. I constructed a simple JUnit test which tries to get a string from strings.xml (just to see if Robolectric works for my project) like this:

1
2
3
4
5
6
7
8
9
10
java

(RobolectricTestRunner.class)

public class RoboStringTest {



    public void getStringFromResources() {

        Context context = RuntimeEnvironment.systemContext;

        String actual = context.getString(R.string.error);

        assertEquals("Error", actual);

    }

}

But it throws an exception:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
No package ID 7f found for ID 0x7f0e005d.



android.content.res.Resources$NotFoundException: String resource ID #0x7f0e005d



    at android.content.res.Resources.getText(Resources.java:348)

    at android.content.res.Resources.getString(Resources.java:441)

    at android.content.Context.getString(Context.java:578)

    at com.cookedapps.android.dronescout.RoboStringTest.getStringFromResources(RoboStringTest.java:21)

    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

    at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:600)

    at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:260)

    at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:130)

    at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:42)

    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

    at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:84)

    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)

    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)

    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)

    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)

I read every Github issue or Stackoverflow question regarding this problem but all provided solutions did not work for me.

Disabling AAPT2 with

1
android.enableAapt2=false

resulted in the same exception but i think this should not be a problem with Robolectric 4.

What I find interesting is the message

1
"No package ID 7f found for ID 0x7f0e005d."

. This stays the same for ever string I try to get. I don't understand this message. Does it mean that strings.xml could not be found?

What I have tried


  • Added
    1
    testOptions.unitTests.includeAndroidResources = true

    to my

    1
    build.gradle


  • Added
    1
    android.enableUnitTestBinaryResources=true

    to my

    1
    gradle.properties


  • Checked my JUnit Run Config (I am on Linux), Working dir is set to
    1
    $MODULE_DIR$


  • Switched my project to AndroidX

Robolectric & Android Version

Robolectric: 4.0.2
Robolectric-Multidex: 4.0.2
Sdk: 28
BuildTools: 28.0.3
Gradle: 3.2.1
AS: 3.2.1
on Linux Mint 18

该提问来源于开源项目:robolectric/robolectric

Have you tried adding




1
testImplementation 'androidx.test:core:1.0.0'

to the build gradle and then using

1
ApplicationProvider.getApplicationContext();

to get context. I was able to perform file operations with this





   



推荐阅读
  • 本文详细介绍了Java中org.w3c.dom.Text类的splitText()方法,通过多个代码示例展示了其实际应用。该方法用于将文本节点在指定位置拆分为两个节点,并保持在文档树中。 ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • 本文详细探讨了JDBC(Java数据库连接)的内部机制,重点分析其作为服务提供者接口(SPI)框架的应用。通过类图和代码示例,展示了JDBC如何注册驱动程序、建立数据库连接以及执行SQL查询的过程。 ... [详细]
  • 在编译BSP包过程中,遇到了一个与 'gets' 函数相关的编译错误。该问题通常发生在较新的编译环境中,由于 'gets' 函数已被弃用并视为安全漏洞。本文将详细介绍如何通过修改源代码和配置文件来解决这一问题。 ... [详细]
  • 深入解析 Android IPC 中的 Messenger 机制
    本文详细介绍了 Android 中基于消息传递的进程间通信(IPC)机制——Messenger。通过实例和源码分析,帮助开发者更好地理解和使用这一高效的通信工具。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • 前言--页数多了以后需要指定到某一页(只做了功能,样式没有细调)html ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • Android 渐变圆环加载控件实现
    本文介绍了如何在 Android 中创建一个自定义的渐变圆环加载控件,该控件已在多个知名应用中使用。我们将详细探讨其工作原理和实现方法。 ... [详细]
  • 扫描线三巨头 hdu1928hdu 1255  hdu 1542 [POJ 1151]
    学习链接:http:blog.csdn.netlwt36articledetails48908031学习扫描线主要学习的是一种扫描的思想,后期可以求解很 ... [详细]
  • 从 .NET 转 Java 的自学之路:IO 流基础篇
    本文详细介绍了 Java 中的 IO 流,包括字节流和字符流的基本概念及其操作方式。探讨了如何处理不同类型的文件数据,并结合编码机制确保字符数据的正确读写。同时,文中还涵盖了装饰设计模式的应用,以及多种常见的 IO 操作实例。 ... [详细]
  • ssm框架整合及工程分层1.先创建一个新的project1.1配置pom.xml ... [详细]
  • 本文详细探讨了 org.apache.hadoop.ha.HAServiceTarget 类中的 checkFencingConfigured 方法,包括其功能、应用场景及代码示例。通过实际代码片段,帮助开发者更好地理解和使用该方法。 ... [详细]
author-avatar
手机用户2502855477
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有