Handling Errors
Type of errors:
- ERR_01: No permission to access external storage - Missing permissions for Croissant app
- ERR_02: Incorrect path provided - Incorrect path of directory/file
- ERR_03: Unknown command - You provide incorrect command
Method to catch error
In page List I already provided example how to catch errors, in this page I'll give you it again.
This is just trying to get an error from JSONArray/Object by key 'error':
Java
private boolean error(JSONArray jsonArray) {
try {
JSONObject error = jsonArray.getJSONObject(0);
error.getString("error");
return true;
} catch (JSONException e) {
return false;
}
}
//......calling it from list or get permissions method...... \\
JSONArray jsonArray = new JSONArray(cursor.getString(dataIndex));
if (error(jsonArray)) {
System.out.println("Error: " + jsonArray.getJSONObject(0).getString("error"));
return;
}
I think all is understandable
That's it! Go to the Start page