Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid SQLiteHelper problem
    text
    copied!<p>I am learning how to make Android apps, and the app I am working on needs a database that is filled at startup, then only read from.</p> <p>I am getting an error at start-up when trying to get an SQLiteDatabase instance.</p> <p>My DatabaseManager Constructor:</p> <pre><code>public DatabaseManager(Context context) { Log.d("Database Manager", "Database Manager Constructor"); CustomSQLiteOpenHelper helper = new CustomSQLiteOpenHelper(context); db = helper.getReadableDatabase(); Log.d("Database Manager", db.toString()); Log.d("Database ", db.getPath()); } </code></pre> <p>The error is in the line where I try the getReadableDatabase() method.</p> <p>This is a stub from my SQLiteHelper class, if it is usefull:</p> <pre><code>public class CustomSQLiteOpenHelper extends SQLiteOpenHelper { public CustomSQLiteOpenHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); Log.d("Database Manager", "Helper Constructor"); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase db) { Log.v("Database Manager", "In onCreate Method"); //deleteAllTables(db); initializeTables(db); fillMonstersTable(db); } } </code></pre> <p>LogCat when I get the error:</p> <pre><code>ERROR/AndroidRuntime(366): FATAL EXCEPTION: main ERROR/AndroidRuntime(366): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{dk.thediabloman.descenthelper/dk.thediabloman.descenthelper.DescentApp}: java.lang.NullPointerException ERROR/AndroidRuntime(366): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585) ERROR/AndroidRuntime(366): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) ERROR/AndroidRuntime(366): at android.app.ActivityThread.access$2300(ActivityThread.java:125) ERROR/AndroidRuntime(366): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) ERROR/AndroidRuntime(366): at android.os.Handler.dispatchMessage(Handler.java:99) ERROR/AndroidRuntime(366): at android.os.Looper.loop(Looper.java:123) ERROR/AndroidRuntime(366): at android.app.ActivityThread.main(ActivityThread.java:4627) ERROR/AndroidRuntime(366): at java.lang.reflect.Method.invokeNative(Native Method) ERROR/AndroidRuntime(366): at java.lang.reflect.Method.invoke(Method.java:521) ERROR/AndroidRuntime(366): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) ERROR/AndroidRuntime(366): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) ERROR/AndroidRuntime(366): at dalvik.system.NativeStart.main(Native Method) ERROR/AndroidRuntime(366): Caused by: java.lang.NullPointerException ERROR/AndroidRuntime(366): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203) ERROR/AndroidRuntime(366): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98) ERROR/AndroidRuntime(366): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:158) ERROR/AndroidRuntime(366): at dk.thediabloman.descenthelper.DatabaseManager.&lt;init&gt;(DatabaseManager.java:52) ERROR/AndroidRuntime(366): at dk.thediabloman.descenthelper.DescentApp.&lt;init&gt;(DescentApp.java:18) ERROR/AndroidRuntime(366): at java.lang.Class.newInstanceImpl(Native Method) ERROR/AndroidRuntime(366): at java.lang.Class.newInstance(Class.java:1429) ERROR/AndroidRuntime(366): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) ERROR/AndroidRuntime(366): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577) </code></pre> <p>Thanks for the help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload