Java – why resources Will getstringarray (int) throw an exception?

I'll call you

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

I know that the resource array exists (because I can reference it with an automatically generated r file), but it continues to throw resourcenotfoundexception

What may cause this situation and what can I do to solve this problem?

I used similar code elsewhere to retrieve an int array, but this code always failed in my unit tests

Solution

This is because resources Getsystem () returns the wrong resources object From document:

Therefore, although r.array Xmlnetworkfiles is the defined resource value for the application, but you requested a system resource and could not find it

Use getresource() (from activity subclass) or getcontext() Getresources() (from view class)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>