時,我不斷收到此錯誤錯誤創建進入SQLdatabase
07-19 14:24:50.840: ERROR/AndroidRuntime(1512): java.lang.NullPointerException
07-19 14:24:50.840: ERROR/AndroidRuntime(1512): at com.fttech.organizeit.TaskHelper.createLunch(TaskHelper.java:76)
07-19 14:24:50.840: ERROR/AndroidRuntime(1512): at com.fttech.organizeit.TaskDetails.saveState(TaskDetails.java:260)
這裏是我的createLunch()
}
public long createTask(String title, String descrip, String type, String taskdatetime){
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_TITLE, title);
initialValues.put(KEY_DESCRIP, descrip);
initialValues.put(KEY_TYPE, type);
initialValues.put(KEY_DATE_TIME, taskdatetime);
return mDb.insert(DATABASE_TABLE, null, initialValues);
}
它給了我在createLunch一個錯誤之前saveState和這樣的IM相當肯定錯誤的謊言這裏。它指着我的回覆聲明。我只是沒有看到問題是什麼。
林看到了保存在這裏的lob.v。但不適用於插入到數據庫中。我認爲錯誤就出在這裏
Log.v(title, "saved");
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
String taskdatetime = dateTimeFormat.format(mCalendar.getTime());
if(taskId == null){
long id = helper.createTask(title, descrip, type, taskdatetime);
Log.v(taskdatetime, "Inserted into databse");
if(id >0){
taskId = id;
}
}
else{
helper.updateTask(taskId, title, descrip, type, taskdatetime);
}
finish();
}
}
public void fillData(){
helper.open();
Cursor task = helper.fetchAllTask();
startManagingCursor(task);
String[] from = new String[]{TaskHelper.KEY_TITLE};
int[] to = new int[]{R.layout.row};
SimpleCursorAdapter taskAdapter = new SimpleCursorAdapter(this, R.layout.list, task, from , to);
setListAdapter(taskAdapter);
}
這工作,但它並不在我的列表中的保存後填充? – yoshi24
這意味着你不打開你的數據庫。 – Merlin
我在我的問題的底部貼的代碼片段。在我的filldata方法中,我在那裏打開數據庫。這是我的填充名單 – yoshi24