I'm trying to write a code that I can try a JSON object and if it's the wrong format inform the user somehow.
The code is :
public boolean sjekkSporingsNummer (JSONObject object){ //object is passed correct
Boolean riktigSporing = null;
riktigSporing = true; //riktig sporing is set to true
//if its true the json is correct
try {
JSONArray consignmentSet = object.getJSONArray("consignmentSet");
JSONObject object1 = consignmentSet.getJSONObject(0);
riktigSporing = true;
}catch (Exception e){ //skips straigt to here
e.printStackTrace();
riktigSporing = false;
}
return riktigSporing;
After if failes with :
07-31 12:34:07.243 15479-15479/com.example.posten E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
What seems wierd to me is that my app skips the try and goes straight to the return statement.
I would like it to try and of it failes set "riktigSporing" to false.
What am I doing wrong?