日历成功保存。但编辑事件强制关闭错误

时间:2012-03-25 05:24:59

标签: android eclipse calendar

我正在尝试使用Android应用程序添加日历事件。事件成功保存。但是当我尝试在日历中编辑该事件时。我收到Force Close错误。

       String calId = "";
        Cursor userCursor =getContentResolver().query(Uri.parse(content://com.android.calendar/calendars),null, null, null, null);
        if(userCursor.getCount() > 0){
            userCursor.moveToFirst();
            calId = userCursor.getString(userCursor.getColumnIndex("_id"));
            }
        ContentValues event = new ContentValues();
        event.put("title", "title");
        event.put("description", "description");
        event.put("eventLocation", "Event Location");
        event.put("allDay", 0);
        event.put("hasAlarm",0);
        event.put("calendar_id",calId);
        Calendar mCalendar = Calendar.getInstance();
        mCalendar.set(2012, 2, 27,7,00,00);
        long start = mCalendar.getTimeInMillis();
        mCalendar.set(2012, 2, 27,8,00,00);
        long end = mCalendar.getTimeInMillis();
        event.put("dtstart",  start);
        event.put("dtend", end);


        Uri newEvent = Uri.parse(content://com.android.calendar/events);
        getContentResolver().insert(newEvent, event);
        ContentValues values = new ContentValues();
        userCursor.close();

但是当我改变event.put(“allDay”,0)时; to event.put(“allDay”,1); 事件成功保存并成功编辑。

我该如何解决?

使用2.3.5设备。感谢任何帮助。感谢。

记录?你的意思是这个?

03-25 23:13:00.150: E/AndroidRuntime(7432): FATAL EXCEPTION: main
03-25 23:13:00.150: E/AndroidRuntime(7432): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.calendar/com.android.calendar.EditEvent}: java.lang.NullPointerException
03-25 23:13:00.150: E/AndroidRuntime(7432):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at android.app.ActivityThread.access$1500(ActivityThread.java:121)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at android.os.Looper.loop(Looper.java:130)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at android.app.ActivityThread.main(ActivityThread.java:3701)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at java.lang.reflect.Method.invokeNative(Native Method)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at java.lang.reflect.Method.invoke(Method.java:507)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at dalvik.system.NativeStart.main(Native Method)
03-25 23:13:00.150: E/AndroidRuntime(7432): Caused by: java.lang.NullPointerException
03-25 23:13:00.150: E/AndroidRuntime(7432):     at java.util.TimeZone.getTimeZone(TimeZone.java:286)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at com.android.calendar.TimezoneAdapter.showInitialTimezones(TimezoneAdapter.java:255)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at com.android.calendar.TimezoneAdapter.<init>(TimezoneAdapter.java:198)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at com.android.calendar.EditEvent.init(EditEvent.java:755)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at com.android.calendar.EditEvent.onCreate(EditEvent.java:675)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-25 23:13:00.150: E/AndroidRuntime(7432):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
03-25 23:13:00.150: E/AndroidRuntime(7432):     ... 11 more
03-25 23:13:00.160: W/ActivityManager(245):   Force finishing activity com.android.calendar/.EditEvent
03-25 23:13:00.670: W/ActivityManager(245): Activity pause timeout for HistoryRecord{2b47e518 com.android.calendar/.EditEvent}

1 个答案:

答案 0 :(得分:0)

嗯......我成功编辑了活动。

03-25 23:13:00.150: E/AndroidRuntime(7432): Caused by: java.lang.NullPointerException
03-25 23:13:00.150: E/AndroidRuntime(7432): at java.util.TimeZone.getTimeZone(TimeZone.java:286)

没有设置时区。

所以它只需要加入一行

    event.put("eventTimezone", Time.getCurrentTimezone());

可以正确编辑事件。