No such SQLite Android table

I built a database helper class using the open () method and the sqlite extended helper with overridden onCreate (). (shown below). Despite all this, I get an SQLiteException error, not such a table. I do not understand why openHelper does not help?

public void open() {
    try{
        db = openHelper.getWritableDatabase();
    } catch (SQLiteException e) {
        db = openHelper.getReadableDatabase();
    }
}

//other stuff

public static final String database_create = "create table " + database_table + " (" + primary_key + " integer primary key autoincrement, " 
    + company_column + " text not null, " + product_column + " text not null);";

    @Override
    public void onCreate(SQLiteDatabase _db) {
        _db.execSQL(database_create);
    }

The following code is intended to temporarily insert a record because the database cannot be empty for other reasons. It seems to be executed perfectly, but the last bit of code that appears after that causes an error

CompanyAndProductDatabaseAdapter cpdAdapter = new CompanyAndProductDatabaseAdapter(this);
    cpdAdapter.open();
    errorguard = cpdAdapter.insertPair("Loading", "...");
    cpdAdapter.close();

//other stuff

cpdAdapter.open();
    Cursor cursor = cpdAdapter.getAllPairsCursor(); //error here
    cursor.requery();
    startManagingCursor(cursor);
+3
source share
2 answers

I don’t know why you implemented the openmethod, also database_createnot what it should be.
I assume the first code is part CompanyAndProductDatabaseAdapter.

:
Android - Sqlite undefined fot

, / SQLiteOpenHelper.

+2

:

    db = openHelper.getWritableDatabase();
    db = openHelper.getReadableDatabase();

/ . , ( ), .

-: :

String myPath = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE); // or OPEN_READONLY, depending on situation.
+1

Source: https://habr.com/ru/post/1791921/


All Articles