android - getWriteableDatabase() throws Null Pointer Exception -
i'm getting crash when trying open sqlitedatabase have writing null pointer exception. here's how instantiate sqliteopenhelper:
private final openhelper mopenhelper; public static datamanager getinstance() { if (sinstance == null) { sinstance = new datamanager(); } return sinstance; } private datamanager() { mopenhelper = new openhelper(mainapp.getinstance(), mainapp.getinstance().getwallettoken()); sqlitedatabase.loadlibs(mainapp.getinstance()); } where mainapp application object.
here's i'm trying do:
sqlitedatabase db = null; try { db = mopenhelper.getwritabledatabase(); (card card : cards) { if (card == null) { continue; } addcard(card, db); contentvalues values = new contentvalues(); values.put(dataentry.column_name_nickname, card.getnickname()); file imagefile = getimagefile(integer.tostring(card.getindex())); if (imageutils.saveimage(card.getcardimage(), imagefile)) { values.put(dataentry.column_name_image_file, imagefile.getabsolutepath()); } string whereclause = dataentry.column_name_card_index + " = " + card.getindex(); db.update(dataentry.table_name, values, whereclause, null); } } { if (db != null) { db.close(); } } and here's crash output:
03-10 16:49:10.533: e/androidruntime(8771): fatal exception: main 03-10 16:49:10.533: e/androidruntime(8771): java.lang.nullpointerexception 03-10 16:49:10.533: e/androidruntime(8771): @ net.sqlcipher.database.sqlitedatabase.<init>(sqlitedatabase.java:1957) 03-10 16:49:10.533: e/androidruntime(8771): @ net.sqlcipher.database.sqlitedatabase.opendatabase(sqlitedatabase.java:901) 03-10 16:49:10.533: e/androidruntime(8771): @ net.sqlcipher.database.sqlitedatabase.openorcreatedatabase(sqlitedatabase.java:944) 03-10 16:49:10.533: e/androidruntime(8771): @ net.sqlcipher.database.sqliteopenhelper.getwritabledatabase(sqliteopenhelper.java:107) 03-10 16:49:10.533: e/androidruntime(8771): @ com.mywebsite.datamanager$openhelper.getwritabledatabase(datamanager.java:282) i googled source code particular line doesn't contain should throw exception. doing wrong?
i'd call loadlibs() before new openhelper().
beyond that, guess getwallettoken() returning null. mainapp.getinstance() not returning null, otherwise crashing on getwallettoken() call itself. how user providing "wallet token"?
Comments
Post a Comment