illegal Property webservice

Asked

Viewed 110 times

2

I’m having a problem at the time of consuming my webservice.

I have the following method (This method will return all users registered in the webservice that are in the database) User has (id,name):

public ArrayList<Usuario> buscarTodosUsuario(){ 

    ArrayList<Usuario> lista = new ArrayList<Usuario>();

    SoapObject buscarUsuario = new SoapObject(NAMESPACE, BUSCARTODOS);

    SoapSerializationEnvelope envelope= new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(buscarUsuario);
    envelope.implicitTypes = true;

    HttpTransportSE http = new HttpTransportSE(URL);

    try {
        http.call("urn= "  + BUSCARTODOS, envelope);

        Vector<SoapObject> resposta = (Vector<SoapObject>) envelope.getResponse();

        for (SoapObject soapObject : resposta) {
            Usuario user = new Usuario();
            user.setIdUsuario(Integer.parseInt(soapObject.getProperty("id").toString()));
            user.setNome(soapObject.getProperty("nome").toString());
            lista.add(user);                
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return lista;
}

The call of the method is:

ArrayList<Usuario> lista = dao.buscarTodosUsuario();
Log.d("ExemploWS", lista + "");

The mistake is:

inserir a descrição da imagem aqui

The User class is:

package com.example.testawebservice;

public class Usuario{
    private int id;
    private String nomeusuario;

    public Usuario(){
    }

    public Usuario(int id, String nomeusuario) {
        super();
        this.id = id;
        this.nomeusuario = nomeusuario;
    }

    public int getIdUsuario() {
        return id;
    }

    public void setIdUsuario(int id) {
        this.id = id;
    }

    public String getNome() {
        return nomeusuario;
    }

    public void setNome(String nomeusuario) {
        this.nomeusuario = nomeusuario;
    }

    @Override
    public String toString() {
        return "Usuario [id=" + id + ", nomeusuario="
                + nomeusuario + "]";
    }
}
  • 1

    You have an error in the line user.setIdUsuario(Integer.parseInt(soapObject.getProperty("id").toString()));. Could [Edit] your question and add the class code Usuario?

  • I edited and put the user class! I have the perception that it really is something with this attribute in specific, because with the "Username" had no problem

  • If you change the line in question and put: System.out.println(soapObject.getProperty(0)); in its place, what is printed on the console?

  • Number 6 appears. That is the ID of my first user registered in the bank! And the same error starts to appear, only now for the other attribute, username.

  • I don’t know how you define these propertys, but something tells me you’re not getting a "name" for them, one solution is you use 0 for the id and 1 to the nomeUsuario, if you do not want to do so need to see where you make this association of the name of property with the attribute of your POJO Usuario. PS: I have no idea how to use this ksoap, so there is no way I can tell you where it is done, if you know add in your reply this class/configuration file or wherever you configure these guys.

  • 1

    Thanks for the help Math... I just found out... Actually it was focused on the method and the user class, but the problem is that in the webservice it was like "idUsuario" and "nounUsuario", when KSOAP tries to take the property "idusuario" or "nomeusuario" it could not find, because of a capital "u"! Thanks for your help!

Show 1 more comment
No answers

Browser other questions tagged

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