Anix PasBesoin Anix PasBesoin - 6 months ago 11
Android Question

App crashing when fetching from string ressources

I have a string array in the string.xml ressources;

<string-array name="errors_signup">
<item>sign up successful!</item>
<item>Invalid username!\n(more than 4 charcaters have to be used)</item>
<item>Username already token!\n(Change it)</item>
<item>Invalid EMail address!</item>
<item>EMail already used!\n(Choose another one)</item>
<item>Invalid passowrd\n(more than 4 charcaters have to be used)</item>
<item>Couldn\'t create the account!\n(try again)</item>
<item>Password dont match\n(the password and it confirmation must be identic)</item>
</string-array>


And I am trying to fetch it by the following code:

private String [] errorsSignup = getResources().getStringArray(R.array.errors_signup);


Running the above code immediately crashes the app. Any explanation?
Here is the log:

05-06 02:22:18.941: D/dalvikvm(4111): GC_EXTERNAL_ALLOC freed 111K, 47% free 2913K/5447K, external 1033K/1036K, paused 63ms
05-06 02:22:19.066: W/dalvikvm(4111): threadid=1: thread exiting with uncaught exception (group=0x40018578)
05-06 02:22:19.073: E/AndroidRuntime(4111): FATAL EXCEPTION: main
05-06 02:22:19.073: E/AndroidRuntime(4111): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.CheesyDev.penpal/com.CheesyDev.penpal.A1_signup}: java.lang.NullPointerException

Answer

The problem was that the errorsSignup array wasn't being initialized: Like it is shown here Thanks to Rembo for this help!