SQLite Insert NullException?
For some reason my code returns a NullException when trying to insert into a table? I am extremely confused.
try{
if(contactsh.selectAll().size() > 0){
for(int i = 0; i < contactsh开发者_Go百科.selectAll().size() - 1; i++){
names[i] = contactsh.selectAll().get(i);
}
} else {
}
} catch(Exception e){
contactsh.insert("Example"); //ERROR IS HERE
timeh.insert("20:20");
dateh.insert("06/27/27");
txth.insert("1-555-555-5555");
Log.w("initiate contacts error: ", e.toString());
}
Error:
06-19 11:29:55.486: ERROR/AndroidRuntime(9482): Caused by: java.lang.NullPointerException
06-19 11:29:55.486: ERROR/AndroidRuntime(9482): at com.laytproducts.timexter.mainAct.onCreate(mainAct.java:57)
06-19 11:29:55.486: ERROR/AndroidRuntime(9482): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-19 11:29:55.486: ERROR/AndroidRuntime(9482): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
06-19 11:29:55.486: ERROR/AndroidRuntime(9482): ... 11 more
Here is my insert method in my class for the DatabaseHelper:
public long insert(String name){
this.insertStmt.bindString(1, name);
return this.insertStmt.executeInsert();
}
If you need to see my whole class I will be more than happy to post it here.
Will probably need to see more code, but I expect either this.insertStmt
is null or contactsh
is null.
精彩评论