Android ormlite

Asked

Viewed 70 times

1

I’m having a problem recording a login in the database, when I call create it returns me Null, what could I have done wrong? Remembering that when I give a LOG to see the login, it shows me the data that were informed, just do not write in the database.

public class Login implements KvmSerializable, EntidadePersitivel {

    @DatabaseField(generatedId = true)
    private int id;
    @DatabaseField
    private String permissoes;

    @DatabaseField
    public String usuario;

    @DatabaseField
    private int codigoCliente;

    public int getCodigoCliente() {
        return codigoCliente;
    }

    public void setCodigoCliente(int codigoCliente) {
        this.codigoCliente = codigoCliente;
    }

    public String getPermissoes() {
        return permissoes;
    }

    public void setPermissoes(String permissoes) {
        this.permissoes = permissoes;
    }

    @DatabaseField

    public String senha;

    @Override
    public Object getProperty(int i) {
        switch (i){
            case 0:
                return this.usuario;
            case 1:
                return this.senha;
        }

        return null;
    }

    @Override
    public int getPropertyCount() {
        return 2;
    }

    @Override
    public void setProperty(int i, Object o) {
        switch (i){
            case 0:
                usuario= o.toString();
                break;
            case 1:
                senha=o.toString();
                break;
            default:break;
        }

    }

    @Override
    public void getPropertyInfo(int i, Hashtable hashtable, PropertyInfo propertyInfo) {
        switch (i){
            case 0:
                propertyInfo.type= PropertyInfo.STRING_CLASS;
                propertyInfo.name="Usuario";
                break;
            case 1:
                propertyInfo.type= PropertyInfo.STRING_CLASS;
                propertyInfo.name="Senha";
                break;
            default:break;
        }
    }

    @Override
    public int getId() {
        return id;
    }

    @Override
    public void setId(int id) {
       this.id=id;
    }
}

Code I’m calling from Logindao to create this new user.

 @Override
    public void onClick(View v) {
        dialog = ProgressDialog.show(LoginActivity.this,
                "Aguarde","Fazendo Login",true);

        new Thread(new Runnable() {
            @Override
            public void run() {
                LoginSerealizable login = new LoginSerealizable();


                login.usuario=  edtUsuario.getText().toString();
                login.senha = edtSenha.getText().toString();



                WebService ws = new WebService();
                try {
                    ws.loginCentral(login);
                    login.setPermissoes(ws.permissoes);
                    login.setCodigoCliente(ws.codigoCliente);

                   loginDAO.create(login);

                    /*Log.d("Chave",ws.chaveDeIntegracao);
                    Log.d("Codigo do cliente", String.valueOf(ws.codigoCliente));
                    Log.d("Permissoes" ,ws.permissoes);
                    */

                    Log.d("Script criação de login","cadastrado");
                    Log.d("Script","id"+ login.getId()+" usuario"+login.usuario +" Permissoes"+login.getPermissoes()+" codigo cliente "+login.getCodigoCliente());

                    Intent it = new Intent(LoginActivity.this,MenuActivity.class);
                    startActivity(it);


                } catch (IOException e) {
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    e.printStackTrace();
                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    dialog.dismiss();
                }
            }

        }).start();
    }

In this log I see the information I passed

D/Script criação de login: cadastrado
10-28 15:49:32.186 10025-10167/routerbox.com.br.centraisdoassinante D/Script: id0 usuariowagner Permissoes70,73,77,75,71,72,50,1,90,93 codigo cliente 8

Error of which returns

10-28 15:57:37.290 17045-17134/routerbox.com.br.centraisdoassinante E/AndroidRuntime: FATAL EXCEPTION: Thread-167
                                                                                      java.lang.NullPointerException
                                                                                          at routerbox.com.br.centraisdoassinante.LoginActivity$1.run(LoginActivity.java:70)
                                                                                          at java.lang.Thread.run(Thread.java:841)

1 answer

0


The Login class was missing the annotation

@DatabaseTable(tableName=Login)

Browser other questions tagged

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