sqlite - .insert() & .execSQL() causing NULL Pointer Exception in Android -


i keep getting null pointer exception via execution of insert statement.

all trying insert new row tbl_building table.

here code:

declaring database:

sqlitedatabase sampledb; 

to retreive context database:

if(value == "retrieve"){     sampledb = getbasecontext().openorcreatedatabase(clientlist.retrievedclient+".db", mode_private, null); }  else if (value == "create"){     sampledb = getbasecontext().openorcreatedatabase(createclient.createdclient+".db", mode_private, null); } 

to insert data table:

            templateselected = 0;              try {                 templateselected = integer.parseint(selectedtemplate.tostring());                 log.e("int : ", selectedtemplate);             }              catch(numberformatexception nfe) {                 string error = nfe.tostring();                 log.e("could not parse: ", error);             }              for(int = 0; < templateselected; i++){                 int buildingname = i+1;                 string buildingnametwo = "b"+buildingname;                 string buildingdesc = "template description";                 string rooftype = "flat - insulated";                 string roofpitchdepth = "5";                  string walltype = "cavity - insulated";                 string coolingtype = "natural";                 string wattage = "wattage";                 string radio = "radio";                  contentvalues args = new contentvalues();                 args.put("buildingname", buildingnametwo);                 args.put("buildingdesc", buildingdesc);                 args.put("rooftype", rooftype);                 args.put("roofpitchdepth", roofpitchdepth);                 args.put("walltype", walltype);                 args.put("coolingtype", coolingtype);                 args.put("localcoolingwattage", wattage);                 args.put("localcoolingcontrols", radio);                  log.e("building name", buildingnametwo);                 log.e("building description", buildingdesc);                 log.e("roof type", rooftype);                 log.e("roof pitch depth", roofpitchdepth);                 log.e("wall type", walltype);                 log.e("cooling type", coolingtype);                 log.e("wattage", wattage);                 log.e("radio", radio);                  //sampledb.insert("tbl_building", null, args);                  try{                     sampledb.execsql("insert tbl_building (b_id, buildingname, buildingdesc, rooftype, roofpitchdepth, walltype, coolingtype, localcoolingwattage, localcoolingcontrols) values ('123','"+buildingnametwo+"','"+buildingdesc+"','"+rooftype+"','"+roofpitchdepth+"','"+walltype+"','"+coolingtype+"','"+wattage+"','"+radio+"')");                  }                 catch(){                 }             }              sampledb.close(); 

my stack trace:

    08-13 13:34:46.280: e/building name(4956): b1 08-13 13:34:46.280: e/building description(4956): template description 08-13 13:34:46.280: e/roof type(4956): flat - insulated 08-13 13:34:46.280: e/roof pitch depth(4956): 5 08-13 13:34:46.280: e/wall type(4956): cavity - insulated 08-13 13:34:46.280: e/cooling type(4956): natural 08-13 13:34:46.280: e/wattage(4956): wattage 08-13 13:34:46.284: e/radio(4956): radio 08-13 13:34:46.292: e/androidruntime(4956): fatal exception: main 08-13 13:34:46.292: e/androidruntime(4956): java.lang.nullpointerexception 08-13 13:34:46.292: e/androidruntime(4956):     @ com.android.sec.buildingtemplatelist$2$1.onclick(buildingtemplatelist.java:125) 08-13 13:34:46.292: e/androidruntime(4956):     @ com.android.internal.app.alertcontroller$buttonhandler.handlemessage(alertcontroller.java:158) 08-13 13:34:46.292: e/androidruntime(4956):     @ android.os.handler.dispatchmessage(handler.java:99) 08-13 13:34:46.292: e/androidruntime(4956):     @ android.os.looper.loop(looper.java:123) 08-13 13:34:46.292: e/androidruntime(4956):     @ android.app.activitythread.main(activitythread.java:4627) 08-13 13:34:46.292: e/androidruntime(4956):     @ java.lang.reflect.method.invokenative(native method) 08-13 13:34:46.292: e/androidruntime(4956):     @ java.lang.reflect.method.invoke(method.java:521) 08-13 13:34:46.292: e/androidruntime(4956):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:871) 08-13 13:34:46.292: e/androidruntime(4956):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:629) 08-13 13:34:46.292: e/androidruntime(4956):     @ dalvik.system.nativestart.main(native method) 

can see problem here?

thanks in advance.

chris

doing this

value == "retrieve" 

compares them objects. compare strings use

value.equals("retrieve") 

otherwise both matches fail , sampledb null.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -