I get from the server array of objects, and by this code I convert it to json:
public static ArrayList<bussListCubic> parseBussinessArray(String result) {
ArrayList<bussListCubic> arr = new ArrayList<bussListCubic>();
try {
JSONArray jArray = new JSONArray(result);
JSONObject json_data = null;
for (int i = 0; i < jArray.length(); i++) {
json_data = jArray.getJSONObject(i);
bussListCubic userInfo = parseBussListCubic(json_data);
arr.add(userInfo);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return arr;
}
Some times the app crashed and this is the error:
Caused by: java.lang.NullPointerException at
org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116) at
org.json.JSONTokener.nextValue(JSONTokener.java:94) at
org.json.JSONArray.<init>(JSONArray.java:87) at
org.json.JSONArray.<init>(JSONArray.java:103)
it is also point that the error with this line :
JSONArray jArray = new JSONArray(result): line #4 in the above code...what does this error mean ?
thank you
adneal
30.9k10 gold badges127 silver badges154 bronze badges
1 Answer 1
The crash is caused by an invalid String result
print the result passed to parseBussinessArray method and see what is its value when crash happens
answered May 3, 2014 at 13:01
Silverstorm
16k2 gold badges43 silver badges53 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
user3516596
actually I also try to send wrong result data"Just for test it", and the app doesn't crash, it just doesn't display anything!!!
Silverstorm
If you use a try catch the error is masked, for this reason the app doesn't crash but doesn't show the values, with wrong input
user3516596
actually now i just try to send null result to parseBussinessArray and I got the same error, so some times the app send null result !!
Silverstorm
I don't know the way you pass result to this method but surely the issue is before, and when result is null cause this problem. You should manage the problem before invoking
parseBussinessArray, adding the appropriate checksdefault
null, and you're trying to use that object as if it wasn't.