热门标签 | 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太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • Java自带的观察者模式及实现方法详解
    本文介绍了Java自带的观察者模式,包括Observer和Observable对象的定义和使用方法。通过添加观察者和设置内部标志位,当被观察者中的事件发生变化时,通知观察者对象并执行相应的操作。实现观察者模式非常简单,只需继承Observable类和实现Observer接口即可。详情请参考Java官方api文档。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文介绍了如何在给定的有序字符序列中插入新字符,并保持序列的有序性。通过示例代码演示了插入过程,以及插入后的字符序列。 ... [详细]
  • JavaSE笔试题-接口、抽象类、多态等问题解答
    本文解答了JavaSE笔试题中关于接口、抽象类、多态等问题。包括Math类的取整数方法、接口是否可继承、抽象类是否可实现接口、抽象类是否可继承具体类、抽象类中是否可以有静态main方法等问题。同时介绍了面向对象的特征,以及Java中实现多态的机制。 ... [详细]
  • 关键词:Golang, Cookie, 跟踪位置, net/http/cookiejar, package main, golang.org/x/net/publicsuffix, io/ioutil, log, net/http, net/http/cookiejar ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • Spring学习(4):Spring管理对象之间的关联关系
    本文是关于Spring学习的第四篇文章,讲述了Spring框架中管理对象之间的关联关系。文章介绍了MessageService类和MessagePrinter类的实现,并解释了它们之间的关联关系。通过学习本文,读者可以了解Spring框架中对象之间的关联关系的概念和实现方式。 ... [详细]
  • 本文介绍了一个Java猜拳小游戏的代码,通过使用Scanner类获取用户输入的拳的数字,并随机生成计算机的拳,然后判断胜负。该游戏可以选择剪刀、石头、布三种拳,通过比较两者的拳来决定胜负。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
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社区 版权所有