0

In my app, I have a database with a table that contains several user made entries. Here's a simplified version of my SQLite database helper class:

public class DatabaseHelper extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "data.db";
    public static final String TABLE_NAME = "log";
    public static final String COL_1 = "ID"; //autoincrement in oncreate
    ...
    public static final String COL_12 = "NUMBER"; //set through getCount()

    public DatabaseHelper(Context context) {
        ...
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        ...
    }

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

    public long getCount() {
        ...
    }

    public boolean insertData(...) {
        ...
    }

    public void update(long id, String param) {
        ...
    }

    public Cursor getAllData() {
        ...
    }

    //for when an entry is deleted and thus COL_12 numbering is not fixed
    public void consolidate() {
        SQLiteDatabase db = this.getWritableDatabase();
        db.execSQL("ALTER TABLE log ORDER BY NUMBER ASC");
    }
}

However, whenever I call myDb.consolidate(), my app crashes. From what I've read from other posts, this should work, but it only throws error code 1: missing database. Anyone know why? Any help is appreciated.

  • How have you made "User Made" entries? Without specifically catering for use outside an app, if I recall correctly, a database is only usable within the app. More on this aspect here [Share SQLite database between 2 android apps?](http://stackoverflow.com/questions/7053809/share-sqlite-database-between-2-android-apps) – MikeT Aug 08 '16 at 01:47
  • Also please show the code for 'onCreate' method. Lastly please include the full log. – MikeT Aug 08 '16 at 01:56
  • The bug is in the `...`. – CL. Aug 08 '16 at 07:38

0 Answers0