I have a program that pulls reports from a system, I'm including one more table in the program. The data that is read comes from an array but sometimes it is empty, and when it does, the program gives error.
I put an if to check if the variable is null
, because if it is, it will take the value of another table.
But when I debugged he accused of error:
Source not found
JSONObject js2 = js.getJSONObject("cliente").getJSONArray("enderecoList").getJSONObject(0);
in this line and the program stops rolling.
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject js = jsonArray.getJSONObject(i);
JSONObject js2 = js.getJSONObject("cliente").getJSONArray("enderecoList").getJSONObject(0);
JSONObject js3;
if (js2 == null){
js3 = js.getJSONObject("unidade").getJSONObject("municipio");
} else {
js3 = js2.getJSONObject("municipio");
}