我在LogCat堆栈中得到了一个NullPointerExcpetion,我似乎无法弄明白为什么。我只希望一些外面的眼睛会帮助我找到问题。
这是来自LogCat的堆栈:
10-28 02:04:55.998: ERROR/AndroidRuntime(524): FATAL EXCEPTION: main
10-28 02:04:55.998: ERROR/AndroidRuntime(524): java.lang.NullPointerException
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at vt.nhw.android.easyringertoggle.ScheduleDbAdapter.createSchedule(ScheduleDbAdapter.java:77)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at vt.nhw.android.easyringertoggle.ScheduleEditActivity.saveState(ScheduleEditActivity.java:195)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at vt.nhw.android.easyringertoggle.ScheduleEditActivity.access$3(ScheduleEditActivity.java:189)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at vt.nhw.android.easyringertoggle.ScheduleEditActivity$5.onClick(ScheduleEditActivity.java:135)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at android.view.View.performClick(View.java:2408)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at android.view.View$PerformClick.run(View.java:8816)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at android.os.Handler.handleCallback(Handler.java:587)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at android.os.Handler.dispatchMessage(Handler.java:92)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at android.os.Looper.loop(Looper.java:123)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at java.lang.reflect.Method.invokeNative(Native Method)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at java.lang.reflect.Method.invoke(Method.java:521)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-28 02:04:55.998: ERROR/AndroidRuntime(524): at dalvik.system.NativeStart.main(Native Method)
堆栈似乎指向saveState()方法和createSchedule()方法。相关的线条是双重的星号。
saveState和():
private void saveState() {
String title = mTitleText.getText().toString();
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
String scheduleDateTime = dateTimeFormat.format(mCalendar.getTime());
if (mRowId == null) {
**long id = mDbHelper.createSchedule(title, scheduleDateTime);**
if(id > 0) {
mRowId = id;
}
} else {
mDbHelper.updateSchedule(mRowId, title, scheduleDateTime);
}
}
createSchedule():
public long createSchedule(String title, String scheduleDateTime) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_TITLE, title);
initialValues.put(KEY_DATE_TIME, scheduleDateTime);
**return mDb.insert(DATABASE_TABLE, null, initialValues);**
}
如果我需要发布任何其他代码,请告诉我。感谢您提供给我的任何帮助。
此致 杰森
答案 0 :(得分:1)
mDb
似乎是NULL,因为这是唯一的全局变量。