Navid
Navid

Reputation: 921

Resources.getSystem().openRawResource gives resource not found exception

In my android app I want to access my text file in static method but using this code:

InputStream is = Resources.getSystem().openRawResource(R.raw.adv_types);

gives me run time exception: resource Not Found Exception

while I can use this code to access the file in non static method:

InputStream is = getResources().openRawResource(R.raw.adv_types);

though its not usable in static method.

Do you have any idea why the first code does not work? And what is the solution to access text file (or resources in general) in static method?

Upvotes: 2

Views: 1791

Answers (1)

Blackbelt
Blackbelt

Reputation: 157457

because Resources.getSystem() give you access only to the system resources not to the application resources. From the documentation:

Return a global shared Resources object that provides access to only system resources (no application resources), and is not configured for the current screen (can not use dimension units, does not change based on orientation, etc).

Upvotes: 6

Related Questions