mercredi 23 décembre 2015

SQLiteAssetHelper failed to upgrade database on OnePlus devices

I get quite alot of Crashlytics report about a NPE when opening and upgrading a database by using SQLiteAssetHelper. I did some research and found out that I am not the only one having this problem on OnePlus devices.

In my app I ship a database in the assets/databases folder, which then get copied to the database path.

Here is my Database class:

public class SQLHelper extends SQLiteAssetHelper {
    private static SQLHelper instance;
    private final Context context;

    private static final String DB_NAME = "database.db";
    private static final int DB_VERSION = 2015122001;

}    private SQLHelper(Context context) {
        super(context, DB_NAME, context.getDatabasePath(DB_NAME).getParent(), null, DB_VERSION);

        this.context = context;

        setForcedUpgrade();
    }
}

As you can see I tried using the Context.getDatabasePath method which should return the path to save the database to. The same error also happens when using the default SQLiteAssetHelper constructor which chooses the database path for you.

The crashlytics report:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.database.sqlite.SQLiteDatabase.setVersion(int)' on a null object reference
       at com.b.a.a.getWritableDatabase(Unknown Source)

This error only happens on OnePlus devices. Is there some fix for this error?

Aucun commentaire:

Enregistrer un commentaire