Couchbase : 'java.io.File android.content.Context.getFilesDir()' on a null object reference -
i using couchbase store database locally on device. have saving database service class.
public void savetodatabase(string symbol, list<date> datelist, list<string> closelist){ cbdatabase db = new cbdatabase(db_name, this); // create object contains data document map<string, object> doccontent = new hashmap<>(); doccontent.put(symbol, symbol); doccontent.put(date, datelist); doccontent.put(close, closelist); string docid = null; try { // 1. create docid = db.create(doccontent); assert(docid != null); txt += ("created doc id " + docid + "\n"); txt += ("\n\nretrieve --> "); // 2. retrieve doccontent= db.retrieve(docid); assert(doccontent != null); txt += ("retrieved doc " + string.valueof(doccontent) + "\n"); txt += ("\n\ndelete --> "); // 4. delete boolean deleted = db.delete(docid); assert(deleted == true); txt += ("deleted document id: " + docid + "\n"); txt += ("\n\nsuccess."); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); }
this cddatabase helper class using couchbase database don't understand might going new couchbase.
public cbdatabase(string dbname, context context){ this.ctx = context; /* manages access databases */ try { manager = new manager( new androidcontext(ctx), manager.default_options ); } catch (ioexception e) { errorchecker.showexception(ctx, r.string.err_create_manager, e ); return; } // create name database , make sure name legal // following characters valid: // abcdefghijklmnopqrstuvwxyz0123456789_$()+-/ if ( ! manager.isvaliddatabasename(dbname)) { errorchecker.showerror( ctx, r.string.err_db_name ); return; } // existing db name // or create new 1 if doesn't exist try { database = manager.getdatabase(dbname); } catch (couchbaseliteexception e) { errorchecker.showexception(ctx, r.string.err_no_db, e ); return; } }
here logcat nullpointer
j
ava.lang.nullpointerexception: attempt invoke virtual method 'java.io.file android.content.context.getfilesdir()' on null object reference com.android.stockhawk w/system.err: @ android.content.contextwrapper.getfilesdir(contextwrapper.java:203) com.android.stockhawk w/system.err: @ com.couchbase.lite.android.androidcontext.getfilesdir(androidcontext.java:40) com.android.stockhawk w/system.err: @ com.couchbase.lite.manager.<init>(manager.java:117) com.android.stockhawk w/system.err: @ com.android.stockhawk.quotes.db.cbdatabase.<init>(cbdatabase.java:41) com.android.stockhawk w/system.err: @ com.android.stockhawk.service.stocktaskservice.savetodatabase(stocktaskservice.java:191) com.android.stockhawk w/system.err: @ com.android.stockhawk.service.stocktaskservice.getstockquotes(stocktaskservice.jcom.android.stockhawk w/system.err: @ com.android.stockhawk.service.stocktaskservice.onruntask(stocktaskservice.java:141) com.android.stockhawk w/system.err: @ com.android.stockhawk.service.stockintentservice.onhandleintent(stockintentservice.java:39)
Comments
Post a Comment