When I call this method in another class it is returning null. But I've debugged the "return listNotes;" line and it's currently being populated.
Method code:
ArrayList<Nota> listNotas = new ArrayList<>();
public ArrayList buscarNotas(String matricula, int etapa){
try {
SoapObject resposta = new SoapObject(NAMESPACE, METHOD_NAME);
resposta.addProperty("Matricula", matricula);
resposta.addProperty("Etapa", etapa);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(resposta);
HttpTransportSE http = new HttpTransportSE(URL);
http.call(SOAP_ACTION, envelope);
String resultado = envelope.getResponse().toString();
JSONArray jsonArray = new JSONArray(resultado);
for(int i=0;i<jsonArray.length();i++ ) {
Nota nota = new Nota();
JSONObject jsonObject =jsonArray.getJSONObject(i);
nota.setDisciplina(jsonObject.getString("Materia"));
nota.setNota(jsonObject.getString("VlrNota"));
listNotas.add(i,nota);
}
} catch (HttpResponseException e) {
e.printStackTrace();
} catch (SoapFault soapFault) {
soapFault.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return listNotas;
}
Call the method in another class. Note: where you are getting null
public List<Nota> baixarNotas (final String matricula, final int etapa){
String msg = "Carregando";
String titulo = "Aguarde";
final ProgressDialog dialog = ProgressDialog.show(this, titulo, msg);
new Thread(new Runnable() {
@Override
public void run() {
try {
listaNotas= notaWS.buscarNotas(matricula,etapa);
} catch (Exception e) {
} finally {
dialog.dismiss();
}
}}).start();
return listaNotas;
}