找不到NullPointerException的原因;安卓

发布于 2024-12-12 08:12:59 字数 3097 浏览 0 评论 0原文

我在 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);**
}

如果我需要发布任何其他代码,请告诉我。感谢您能给我的任何帮助。

问候, 贾森

I have been getting a NullPointerExcpetion in the LogCat stack, and I can't seem to figure out why. I just hope some outside eyes will help me find the issue.

Here is the stack from 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)

The stack seems to be pointing to the saveState() method and the createSchedule() method. The relevant lines have been double asterisked.

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);**
}

Please let me know if I need to post any other code. Thank you for any help that you can give me.

Regards,
Jason

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百思不得你姐 2024-12-19 08:12:59

mDb 似乎为 NULL,因为这是唯一的全局变量。

mDb seems to be NULL because this is the only variable that is global.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文