Hi list, I am trying to develop an application which shall use an SQLiteDatabase to store some objects. I went through several tutorials and also took a look at the notepad example code in the android code section. I always get one and a same exception of which I can't figure out why it happens.
I extended the SQLiteOpenHelper class and in my Activity I try to call the getReadableDatabase() method. When I take a look at the StackTrace of the exception, I can see that it is thrown in ContextWrapper.openOrCreateDatabase(). 09-21 18:07:44.103: ERROR/Homepage Ping(339): null 09-21 18:07:44.103: ERROR/Homepage Ping(339): java.lang.NullPointerException 09-21 18:07:44.103: ERROR/Homepage Ping(339): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java: 193) 09-21 18:07:44.103: ERROR/Homepage Ping(339): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java: 98) 09-21 18:07:44.103: ERROR/Homepage Ping(339): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java: 158) 09-21 18:07:44.103: ERROR/Homepage Ping(339): at de.peterosburg.android.homepagePing.HomepagePing.initializeWebsites(HomepagePing.java: 72) 09-21 18:07:44.103: ERROR/Homepage Ping(339): at de.peterosburg.android.homepagePing.HomepagePing.<init>(HomepagePing.java: 38) 09-21 18:07:44.103: ERROR/Homepage Ping(339): at java.lang.Class.newInstanceImpl(Native Method) 09-21 18:07:44.103: ERROR/Homepage Ping(339): at java.lang.Class.newInstance(Class.java:1479) 09-21 18:07:44.103: ERROR/Homepage Ping(339): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 09-21 18:07:44.103: ERROR/Homepage Ping(339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2409) 09-21 18:07:44.103: ERROR/Homepage Ping(339): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2512) The code of my class looks as follows: public class WebsiteData extends SQLiteOpenHelper { private static final String DATABASE_NAME = SITES_DATABASE_NAME; private static final int DATABASE_VERSION = 1; private static String[] FROM = { _ID, SITE_IDENTIFIER, SITE_URL, }; private static String ORDER_BY = _ID + " ASC"; public WebsiteData(Context cntxt){ super(cntxt, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { Log.w(HomepagePing.tag, "Creating Websites db"); db.execSQL("CREATE TABLE "+ SITES_TABLE_NAME +" (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + SITE_IDENTIFIER + " TEXT NOT NULL " + SITE_URL + " TEXT NOT NULL" + ");"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + SITES_TABLE_NAME); onCreate(db); } } Within my activity I do the following: try{ //this.sites_db = this.openOrCreateDatabase(SITES_DATABASE_NAME, MODE_PRIVATE, null); WebsiteData data = new WebsiteData(this); SQLiteDatabase db = data.getReadableDatabase(); } catch(Exception e){ Log.e(HomepagePing.tag, e.getMessage(), e); } As you can see the Exception is written to the log at exactly this try- catch-block. I squeezed the hell out of Google but couln't find any solution yet. Any help is highly appreciated. I am using an Emulator with API Level 7 (Android2.1-update1) If you need any more information, let me know and I try to share it. Regards, Peter -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en