Problem with return returning null to another class

0

I have a class responsible for downloading a list of students in a web service through a method where I pass as a parameter a string with the Teacher Code and it returns me an Array of students. The problem is that when I call this method in the other class it is returning an empty array.

I have already debug the web service method return and it has all the data, so when I get it in another class it is empty.

Follow the code below:

CLASS WEBSERVICE WITH THE METHOD THAT RETURNS THE STUDENTS

    ArrayList<Aluno> listAlunos = new ArrayList<>();



public ArrayList<Aluno> alunos(String codProfessor){


    try {
        SoapObject resposta = new SoapObject(NAMESPACE, METHOD_NAME);

        resposta.addProperty("CodigoPro", codProfessor);

        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++ ) {
            Aluno aluno = new Aluno();
            JSONObject jsonObject =jsonArray.getJSONObject(i);

            aluno.setMatriculaAluno(jsonObject.getString("Matricula"));
            aluno.setNomeAluno(jsonObject.getString("Nome"));
            aluno.setDisciplinaAluno(jsonObject.getString("CodMat"));
            aluno.setTurmaAluno(jsonObject.getString("CodTur"));

          listAlunos.add(i,aluno); 
        }


    }  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 listAlunos; // FOI REALIZADO O DEBUG DESSA LINHA, ESTÁ OK COM TODOS OS DADOS
}

CLASS WHERE I CALL THE METHOD SO THAT WHEN ACTIVITY IS CREATED IT MAKES IT RECOVER THIS LIST OF STUDENTS AND PASSES TO CLASS DAO.

  AlunoDAO alunoDAO = new AlunoDAO(getBaseContext());
ArrayList<Aluno> listaAlunos = new ArrayList<Aluno>();
AlunoWS alunoWS = new AlunoWS();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menu);

    String nomeProfessor = getIntent().getStringExtra("Professor");

     baixarDados(nomeProfessor);

}


public void baixarDados(final String codProfessor){
    String msg = "Atualizando dados";
    String titulo = "Aguarde";

    final ProgressDialog dialog = ProgressDialog.show(this, titulo, msg);

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {


                listaAlunos = alunoWS.alunos(codProfessor); //LISTA ALUNOS ESTÁ RECEBENDO NULL
                alunoDAO.insereAlunos(listaAlunos);

            } catch (Exception e) {
            } finally {
                dialog.dismiss();
            }
        }
    }).start();


}
    
asked by anonymous 11.09.2016 / 13:40

0 answers