简体   繁体   中英

Missing assets folder and database in apk

I am trying to develop an app with 1 database with 2 tables via a sqliteopenhelper in a databaseadapter class.

    DatabaseHelper myDBHelper;
    private static SQLiteDatabase db;
    private final Context context;

    public DbA(Context ctx) {
        this.context = ctx;
        myDBHelper = new DatabaseHelper(context);
    }

    public DbA open() {
         db = myDBHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        myDBHelper.close();
    }


    private static class DatabaseHelper extends SQLiteOpenHelper
    {

        private static final String K_I = "_id";
    private static final String K_CC = "cc";
                          private static final String T_DGI = "dgi";

    private static final String CREATE_FIRSTTABLE = 
                "create table if not exists firsttable (" + K_I + " integer primary key autoincrement, "
                + K_CC + " text not null, "
                + ");";

    private static final String CREATE_SECONDTABLE =  "create table if not exists secondtable (" 
                                  + K_I + " integer primary key  autoincrement, "
    + T_DGI + " text not null, "
     + ");";

        DatabaseHelper(Context context) {
            super(context, DATABASE, null, D_VERS);
        }

        @Override
        public void onCreate(SQLiteDatabase _db) {


                          try{
_db.execSQL(CREATE_FIRSTTABLE);                
              _db.execSQL(CREATE_SECONDTABLE);

                          }catch(SQLException e)
                                      { e.printStackTrace(); }          
}

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



        }

    }

Along the way, I have extracted the database via the file explorer in the ddms to insert data manually (for both tables) and push it back into eclipse. All this while, the project worked perfectly in the virtual AVD emulator.

But once I try to use an actual android device to run it, it throws an error with a logcat stating that the secondtable was not found?

08-17 01:48:18.951: E/SQLiteLog(4602): (1) no such table: secondtable 08-17 01:48:18.956: D/AndroidRuntime(4602): Shutting down VM 08-17 01:48:18.956: W/dalvikvm(4602): threadid=1: thread exiting with uncaught exception (group=0x41f23700) 08-17 01:48:18.966: E/AndroidRuntime(4602): FATAL EXCEPTION: main

Would really appreciate any ideas as how to go about fixing this.

This is the new logcat reading when clicking on a button within the app that crashes it.. not sure what it means

08-17 02:35:39.631: E/(8527): Device driver API match 08-17 02:35:39.631: E/(8527): Device driver API version: 23 08-17 02:35:39.631: E/(8527): User space API version: 23 08-17 02:35:39.631: E/(8527): mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Wed Oct 30 09:36:10 KST 2013

Uninstall and reinstall the app on your device.

If the problem goes away, that is because:

  • You changed your database schema, adding in secondtable ,

  • You did not update your schema version or implement onUpgrade() of your SQLiteOpenHelper , and

  • Your device already had a version of your app, with a database, created with the earlier schema that lacked secondtable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM