Error requesting the ID of a data in the database via the data STRING name

Asked

Viewed 30 times

1

Good guys, I made a method in my webservice to get the ID of a value of a state, IE, I pass to function a name EX: "Acre" and it returns me the ID in the bank of that state. I did it, it worked cool testing by SOAPUI which is used to test, I wrote "Acre" and he returned me 1, so far so good... I went to implement in my project.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String ObjetoDAO.Estado.toString()' on a null object reference                                                                                  at com.example.scartop.photoprint.frmCadastro.CadastroUsuario(frmCadastro.java:112)

Well my DAO method that seeks this data is:

  public Estado buscaIdEstadoPorNome(String nome){
    Estado est = null;

    SoapObject buscarIdEstado = new SoapObject(NAMESPACE, BUSCAR_ID_ESTADO);

    buscarIdEstado.addProperty("nome", nome);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.setOutputSoapObject(buscarIdEstado);

    envelope.implicitTypes = true;

    HttpTransportSE http = new HttpTransportSE(URL);

    try {
        http.call("urn: " + BUSCAR_ID_ESTADO, envelope);
        SoapObject resposta = (SoapObject) envelope.getResponse();
        est = new Estado();
        est.setID_ESTADO(Integer.parseInt(resposta.getProperty("ID_ESTADO").toString()));

    } catch (Exception e){
        e.printStackTrace();
        return null;
    }
    return est;
}

And I’m using it to return the data:

EstadoDAO estDao = new EstadoDAO();
    Estado est = estDao.buscaIdEstadoPorNome("Acre");
    Log.d("Id Estado: ", est.toString());

Can anyone tell me what is wrong? and why? I thank you from the beginning.

  • Maybe your code is releasing an exception and the catch is running, thus returning null. So when you try to log in calling the Log. d("Id State: ", est.toString()); he launches a Nullpointerexception

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.