unable to copy database using SQLiteAssetHelper class

前端 未结 4 1125
野趣味
野趣味 2021-01-07 06:00

I am extending SQLiteAssetHelper class to use my pre-populated database from assets folder but my app crashed and gave an error saying Caused by: android.

4条回答
  •  迷失自我
    2021-01-07 06:31

    Make sure you have the db file under assets\databases folder in your app, in the main folder.

    Also make sure you have specified the correct database name, so if your file name is data.db, your database name should be data.db.

    public class MyHelperDatabase extends com.readystatesoftware.sqliteasset.SQLiteAssetHelper {
    
        private static final String DATABASE_NAME = "data.db";
    

    Or if you are using Room:

    public abstract class AppDatabase extends RoomDatabase {
    
        private static AppDatabase INSTANCE;
    
        @VisibleForTesting
        public static final String DATABASE_NAME = "data.db";
    

提交回复
热议问题