Error in SQLite query? "No such table: Table (code 1):, while compiling: SELECT Field from Table"

3

Hi, I have a database in SQLite , and I'm trying to query a field integer called Type to make a comparison with the cases of a switch , but it shows me the error:

  

no such table: Table (code 1):, while compiling: SELECT Field from   Table

this is my code:

Cursor cursor=null;
int x=0;
try {
bd=con.getReadableDatabase();
cursor= bd.rawQuery("SELECT Tipo from Tabla", null);//error
x=Integer.parseInt(cursor.getString(0));
}
catch (Exception e)
{
 e.printStackTrace();
}

SQLiteDatabase bd1 = con.getWritableDatabase();
ContentValues registro = new ContentValues();
if(cursor!=null) {
cursor.moveToFirst();
 switch (x) {
     case 1:
     ....
     break;
     }
 }
 ......

Database

public class conexion extends SQLiteOpenHelper{

        public conexion(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)
        {
            super(context, name, factory, version);
        }

        @Override
        public void onCreate(SQLiteDatabase sqLiteDatabase) {
           sqLiteDatabase.execSQL(Tabla.crearT);
        }
        @Override
        public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
            sqLiteDatabase.execSQL("drop table if exists " + Tabla.tabl);

           onCreate(sqLiteDatabase);
        }
    }

Table

public class Creditos_Gestiones {
    //constante campos tabla
    public static final String tabl="Tabla";
    public static final String id="id";
    public static final String Tipo="Tipo";
    public static final String User="User";
    public static final String Nombre="User";

    public static final String creaT = "create table Tabla" + tabl + "(" +id + " integer primary key autoincrement, " + Tipo +" integer, " + User + " integer, " +Nombre+ " text)";
}
    
asked by Geek 21.08.2018 в 17:30
source

1 answer

0

The problem is not in the query, it is in the query that you have defined to create the table:

 public static final String creaT = "create table Tabla" + tabl + "(" +id + " integer primary key autoincrement, " + Tipo +" integer, " + User + " integer, " +Nombre+ " text)";

actually this is not creating the table for that reason you get the error:

  

"no such table: Table (code 1):, while compiling: SELECT Field from   Table "

should be:

 public static final String creaT = "create table " + tabl + " (" +id + " integer primary key autoincrement, " + Tipo +" integer, " + User + " integer, " +Nombre+ " text)";

After correcting the query you must delete the application and install it again or delete the cache to avoid information that could be corrupted.

    
answered by 21.08.2018 / 19:55
source