Calendar gets saved successfully.but edit event force close error

Posted by Jast Vacaty on Stack Overflow See other posts from Stack Overflow or by Jast Vacaty
Published on 2012-03-25T05:24:58Z Indexed on 2012/03/25 5:29 UTC
Read the original article Hit count: 155

Filed under:
|
|

I am trying to add calendar events with my applicatiom. Event gets saved successfully. However when i try to edit that event in Calendar. I get Force Close error.

       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();

But when I change event.put("allDay", 0); to event.put("allDay", 1); Event gets saved successfully and gets edited successfully.

How do I fix it?

Using 2.3.5 device. Appreciate any help. thanks.

© Stack Overflow or respective owner

Related posts about android

Related posts about eclipse