Chris Chris - 1 month ago 4x
Android Question

Android string-array crash

I have a very weird problem with my Android application. Every time I add a string-array to my strings.xml (or any other file in res/values/), my program crashes on start up. I know, with absolute certainty, that this is what is crashing it (since whenever I remove it, it works fine). Anyway, here is the XML code that causes the crash:

<string-array name="main_list">

Is there something wrong with the formatting of it at all? It is inside the "resources" tags and everything. Here is the full XML file:

<?xml version="1.0" encoding="utf-8"?>
<!-- Activity Names -->
<string name="app_name">MyFavs</string>
<!-- Login Vars -->
<string name="username_login_field">Username</string>
<string name="password_login_field">Password</string>
<string name="login_btn">Login!</string>
<string name="remember_login_tag">Save Login Info</string>
<string name="no_username_password">You must supply a username and password</string>
<string name="sign_in_cancelled">Sign-in cancelled</string>
<string name="sign_in_progress">Signing in...</string>
<string name="invalid_username_password_alert_title">Error</string>
<string name="invalid_username_password_alert_btn">Ok</string>
<string name="menu_forgotten_password">Forgot Password?</string>
<!-- ForgotPasswd Vars -->
<string name="forgotten_pass_field">Email</string>
<string name="forgotten_pass_btn">Recover Account</string>
<string name="forgot_passwd_progress">Recovering account...</string>
<string name="invalid_forgot_passwd_title">Recover Account</string>
<string name="invalid_forgot_passwd_btn">Ok</string>
<string name="no_email">You must supply a valid email</string>
<string name="recover_cancelled">Recover cancelled</string>
<string name="menu_home">Home</string>
<string-array name="main_list">

Again, removing the "string-array" section at the bottom makes the program work, but adding it causes a crash.

Here is the logcat crash log (although it doesn't help much):

W/dalvikvm( 849): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime( 849): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 849): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.myfavs.droid/org.myfavs.droid.login}: java.lang.NullPointerException
E/AndroidRuntime( 849): at
E/AndroidRuntime( 849): at
E/AndroidRuntime( 849): at$2200(
E/AndroidRuntime( 849): at$H.handleMessage(
E/AndroidRuntime( 849): at android.os.Handler.dispatchMessage(
E/AndroidRuntime( 849): at android.os.Looper.loop(
E/AndroidRuntime( 849): at
E/AndroidRuntime( 849): at java.lang.reflect.Method.invokeNative(NativeMethod)
E/AndroidRuntime( 849): at java.lang.reflect.Method.invoke(
E/AndroidRuntime( 849): at$
E/AndroidRuntime( 849): at
E/AndroidRuntime( 849): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 849): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 849): at org.myfavs.droid.login.onCreate(
E/AndroidRuntime( 849): at
E/AndroidRuntime( 849): at
E/AndroidRuntime( 849): ... 11 more
I/Process ( 51): Sending signal. PID: 849 SIG: 3

If anyone has any ideas, please share them. I have been working on this for quite a long time, and I'm sure it is a stupid mistake but I just need another pair of eyes. I would be willing to try any possible solution.


I removed every reference to the string-array resource and simply including the resource causes the crash. I don't reference it anywhere, so its not that that is causing the problem.

As requested, here is my onCreate for "login", although I haven't touched that code in a long time and it has always worked:

public void onCreate(Bundle savedInstanceState)
Log.d("Login","onCreate called");
EditText pwd = (EditText)findViewById(;
if (Interactor.getDB().getSetting("save_login").equals("yes"))
// Treat "Send" soft-button on keyboard as a button click
pwd.setOnEditorActionListener(new android.widget.TextView.OnEditorActionListener()
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
if (actionId == EditorInfo.IME_ACTION_SEND)
return true;

The exception is being thrown just by including the resource inside res/values even without ever referencing it. That's why its so weird to me...

EDIT of the EDIT:

Jon Skeet might be on to something. While including the string-array resource, and commenting out line 32 of login's onCreate (as I said what line that is in the comments above), the application works again. So adding a string-array breaks that line somehow? Any help in why adding the string-array resource would break that, but it works 100% without adding the resource?


Surely there is no problem with your string array.Problem is in the code where you are accessing the string

try like this

Resources res = getResources();
String[] list = res.getStringArray(R.array.main_list);