Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get a Resources$NotFoundException when using InstrumentationRegistry.getContext().getString()?

I am running Android Instrumentation tests and when I use the Context returned by InstrumentationRegistry.getContext() to retrieve a string given an id I get the message:

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

I've tried ids from other string resources but to no avail.

I've looked through several questions about this same exception on stackoverflow but all of them involve passing an the string id to View.setText. This is not relevant for me since I am creating a library and there are no Views at all.

like image 985
bartonstanley Avatar asked Aug 25 '16 02:08

bartonstanley


1 Answers

You can use targetContext like in this example:

InstrumentationRegistry.getTargetContext().getString(R.id.name);

This should fetch your string resouces

like image 73
Zeeshan Ashraf Avatar answered Nov 05 '22 05:11

Zeeshan Ashraf