I recently worked on an application which connects and parse data from a webserver into an android device, tested on froyo and gingerbread and works fine but crashes on ICS devices. As for the UI I used gingebread objects so I think it's not the issue.
It works just fine on the first run even after connecting to facebook but errors on the part where it fetch and parse all of the JSON data gathered.
Here's the logcat errors straight from the device:
E/AndroidRuntime(25620): FATAL EXCEPTION: Thread-9660
E/AndroidRuntime(25620): java.lang.UnsupportedOperationException
E/AndroidRuntime(25620): at java.lang.Thread.stop(Thread.java:1076)
E/AndroidRuntime(25620): at java.lang.Thread.stop(Thread.java:1063)
E/AndroidRuntime(25620): at com.android.guestlist.SplashScreen$1.run(Spla
shScreen.java:89)
E/android.os.Debug( 2090): !@Dumpstate > dumpstate -k -t -n -z -d -o /data/log/d
umpstate_app_error
E/Launcher(18546): Error finding setting, default accessibility to not found: ac
cessibility_enabled
E/log_tag (25620): Error in http connection android.os.NetworkOnMainThreadExcept
ion
E/log_tag (25620): Error converting result java.lang.NullPointerException
E/log_tag (25620): Error parsing data org.json.JSONException: End of input at ch
aracter 0 of
E/log_tag (25620): Error in http connection android.os.NetworkOnMainThreadExcept
ion
E/log_tag (25620): Error converting result java.lang.NullPointerException
E/log_tag (25620): Error in http connection android.os.NetworkOnMainThreadExcept
ion
E/log_tag (25620): Error parsing data org.json.JSONException: End of input at ch
aracter 0 of
And here's my JSON parser since I think this is where the problem happens? And oh, the logs I created doesn't even appear of the phone logs Well I can't really say but here is the code:
public void getDataFromWeb(String a, String b){
String result = "";
Log.v(TAG, "Name Value Pair a " + a);
Log.v(TAG, "Name Value Pair b " + b);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("a_param",a));
nameValuePairs.add(new BasicNameValuePair("b_param",b));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://[mywebserviceshere].php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.v(TAG, "connected");
}catch(Exception e){
Log.v(TAG, "run failed");
Log.e("log_tag", "Error in http connection "+e.toString());
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
String line = "0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
Log.v(TAG, "buffered read");
}catch(Exception e){
Log.v(TAG, "buffered error");
Log.e("log_tag", "Error converting result "+e.toString());
}
try{
Log.v(TAG, result);
JSONArray jArray = new JSONArray(result);
JSONObject json_data=null;
for(int i=0;i<jArray.length();i++){
Log.v(TAG, "loop start");
json_data = jArray.getJSONObject(i);
w.add(json_data.getString("w_data"));
x.add(json_data.getString("x_data"));
y.add(json_data.getString("y_data"));
z.add(json_data.getString("y_data"));
Log.v(TAG, "list added");
}
}catch(JSONException e){
w.add("0");
x.add("No Data");
y.add("No Data");
z.add("No Data");
Log.v(TAG, "rest failed");
Log.e("log_tag", "Error parsing data "+e.toString());
}
}
And finally here's exactly what it looks like in AVD:
Is this an issue on ICS or I have to revise some of my codes?