MainActivity.java String[] name = getResources().getStringArray(R.array.name); String.xml <string name="petr">Петр</string> <string name="vasiliy">Василий</string> <string-array name="name"> <item>@string/petr</item> <item>@string/vasiliy</item> </string-array> 

Cannot connect an array from String.xml. Throws Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources ()' on a null object reference.

How can it be null ??? The array is there.

  • Everything works fine. You can use it like this. Yes, and what a difference, just the lines in the array also tried, the same trouble. - Ikibana

1 answer 1

If this

 String[] name = getResources().getStringArray(R.array.name); 

field in the Activity, then you access the resources when you do not know about them yet. Take out array initialization in onCreate

  • It was not a reel. Thanks Dmitry. - Ikibana