SQLiteAssetHelper causes instant crash before even copying the database from the assets folder

后端 未结 1 1202
忘掉有多难
忘掉有多难 2021-01-29 12:20

https://github.com/jgilfelt/android-sqlite-asset-helper

I\'m switching from SQLiteOpenHelper to SQLiteAssetHelper so i can use an existing DB s

相关标签:
1条回答
  • 2021-01-29 12:43

    Do not initialize Activity instance variables that require a Context in their declarations, as the Context will be null. Initialize dbTools inside an appropriate lifecycle method like onCreate:

    DbHelper dbTools;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ...
        dbTools = new DbHelper(this);
    }
    
    0 讨论(0)
提交回复
热议问题