This makes no sense to me, I am getting an index out of bounds exception from some code that fetches and splits a response from the server to determine a users account details and account type.
Crash Report (Reason):
07-06 12:11:30.602 2376-2376/lsa1314.com.zip E/AndroidRuntime: FATAL EXCEPTION: main
Process: lsa1314.com.zip, PID: 2376
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at lsa1314.com.zip.loggedInDefault$2.onResponse(loggedInDefault.java:130)
at lsa1314.com.zip.loggedInDefault$2.onResponse(loggedInDefault.java:120)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Now obviously that is telling me based on looking at the lines around 130 as stated in the report above that I am getting an array index out of bounds exception. This appears to point to when splitting the line of the response from server.
//Split lines to separate response
String[] responseSplitter = response.split(":");
String firstName = responseSplitter[0];
String surname = responseSplitter[1];
String accType = responseSplitter[2];
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
prefs.edit().putString("first_name", firstName).commit();
prefs.edit().putString("surname", surname).commit();
prefs.edit().putString("account_type", accType).commit();
This error is usually caused when there is no index [1,2,3,etc] and I am trying to access it. The only thing that is confusing me is that said index works just fine on a mobile phone but not on a tablet??
I try this in 2 nexus emulators and the phone works but not the tablet. The above error is what the tablet produces.
I doubt it is relevant but I will include what the PHP is returning to the device on the server side incase it is needed:
echo json_encode($firstName . ":" . $surname . ":" . $account_type);