I use my application object (Android block for development) to call the database constructor inside my oncreate method. But I canβt understand why it cannot be created. This is what my code looks like:
my database class, with DbHelper as an inner class:
package com.example.pharmacie; import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class PhData { private static final String TAG = PhData.class.getSimpleName(); private static final int VERSION = 1; private static final String DATABASE = "ph_info.db"; private static final String TABLE = "ph_info"; public static final String C_ID = "_id"; public static final String C_CREATED_AT = "created_at"; public static final String C_NAME = "Pharmacie "; public static final String C_TELE = " "; public static final String C_ADRESS = "Tet"; public static final String C_HAS_SHIFT = "yes";
And here is my application class, where I call the constructor to create my db:
package com.example.pharmacie; import android.app.Application; import android.util.Log; public class PharmacieApplication extends Application { private static final String TAG = PharmacieApplication.class.getSimpleName(); PhData phData; @Override public void onCreate() { super.onCreate(); phData = new PhData(this); Log.d(TAG, "onCreated"); } @Override public void onTerminate() { super.onTerminate(); Log.d(TAG, "onTerminated"); } }
And here is what I get in my logcat:
04-20 03:15:05.968: D/PhData(368): Constructor called 04-20 03:15:05.968: D/PhData(368): Initialized data 04-20 03:15:05.968: D/PharmacieApplication(368): onCreated 04-20 03:15:06.568: D/JoursListActivity(368): onCreated
source share