Android SQLiteOpenHelper is not working

The onCreate void of my SQLiteOpenHelper is not called even when get a databse with “database = helper.getWritableDatabase();”. I read lots of posts on this page here but I didn’t find any soloution that worked for me.

SQLiteOpenHelper:

package eu.michael1011.currencies.sql;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class Helper extends SQLiteOpenHelper {

    public static final String database_name = "currencies.db";

    public static final String col1 = "id";
    public static final String col2 = "value";

    public Helper(Context context) {
        super(context, database_name, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.d("database", "started");

        db.execSQL("create table EUR ("+col1+" TEXT, "+col2+" TEXT)");

        Log.d("database", "finished");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        db.execSQL("drop table if exists EUR");

        onCreate(db);
    }

}

I call it in my main activity like this:

    helper = new Helper(getBaseContext());
    database = helper.getWritableDatabase();

Source: java

Leave a Reply