Why is the resources.getStringArray (int) exception an exception?

I have a call

Resources resources = Resources.getSystem();
String[] networkFiles = resources.getStringArray(R.array.xmlNetworkFiles);

and I know that this resource array exists (since I can reference it with an automatically generated R file), but it keeps throwing ResourceNotFoundException.

What could be causing this and what can I do to fix it?

I used similar code elsewhere to retrieve an array from int, but in my unit tests it always fails.

+3
source share
2 answers

This is because it Resources.getSystem()returns an invalid Resources object. From the documentation:

, ( ) ( ..).

, R.array.xmlNetworkFiles - , , .

getResource() ( Activity) getContext().getResources() ( View).

+5
Resources resources = getResources();
String[] networkFiles = resources.getStringArray(R.array.xmlNetworkFiles);

, , .

+2

Source: https://habr.com/ru/post/1790831/


All Articles