CRUD Android doubts

Asked

Viewed 81 times

1

Good afternoon I’m with 3 doubts regarding a crud I made in my app.

1 I did a field search and it seems that does not pick up any phone of the line J7 and I was wondering if someone can tell me why

2 The crud needs to put something in the Manifest or that of some permission

3 As return a value I placed inside a table

I’ll leave the crud of my app here

Create

public class Create {

    public void createtable() {
        SQLiteDatabase db = Maindb.getInstancia().getWritableDatabase();
        String colunas = "(id INTEGER , valoragua INTEGER , acordar INTERGER ,
        dormir INTERGER )";
        String query = "CREATE TABLE IF NOT EXISTS " + Maindb.TABELA +
            colunas;
        db.execSQL(query);
    }
}

Maindb

public class Maindb extends SQLiteOpenHelper{

    public static final String DATABASE = "bdrespostas";
    public static final  int VERSION = 1;
    public static final String TABELA = "respostasAguaCasa";
    public static Maindb instancia;

    public static  Maindb   getInstancia(){
        if(instancia == null) instancia = new Maindb();
        return instancia;
    }

    private Maindb( ){
      super(Myapp.getContext() , DATABASE,null , VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

Myapp

private static Context context;

@Override
public void onCreate() {
    context = getApplicationContext();
    super.onCreate();
}

public static Context getContext() {
    return context;
}

Read

public class Read {
      public ArrayList<RespostasAguaCasa> getLista() {
            SQLiteDatabase db =
                Maindb.getInstancia().getWritableDatabase();
            String query = "SELECT * FROM " + Maindb.TABELA;
            ArrayList<RespostasAguaCasa> lista = new ArrayList<>();

            Cursor c = db.rawQuery(query, null);
            if (c.moveToFirst()) {

              do {
                RespostasAguaCasa resp = new RespostasAguaCasa(c.getString(0));

                resp.setValoragua(c.getInt(1));
                resp.setAcordar(c.getInt(2));
                resp.setDormir(c.getInt(3));
                lista.add(resp);
              }
              while (c.moveToNext());
              {
              }
            }
            c.close();
            return lista;
      }
}

Update

public class Create {

    public void createtable() {
        SQLiteDatabase db = Maindb.getInstancia().getWritableDatabase();
        String colunas  = "(id INTEGER , valoragua INTEGER , acordar
        INTERGER , dormir INTERGER )";
        String query  = "CREATE TABLE IF NOT EXISTS " + Maindb.TABELA +
            colunas;
        db.execSQL(query);

    }
}
  • Did you have any error code in any of the 3 cases?

  • only the error in line J7 qu and the application to

No answers

Browser other questions tagged

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