我在更新日历活动时遇到了一些问题。这是我用来插入它的代码:
long calID = 1;
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
startMillis = beginTime.getTimeInMillis()+5000;
endMillis = startMillis+1000;
ContentResolver cr = getContext().getContentResolver();
values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, startMillis);
values.put(CalendarContract.Events.DTEND, endMillis);
values.put(CalendarContract.Events.TITLE, getReminder());
values.put(CalendarContract.Events.DESCRIPTION, getNote());
values.put(CalendarContract.Events.CALENDAR_ID, calID);
values.put(CalendarContract.Events.EVENT_TIMEZONE, "America/Chicago");
values.put(CalendarContract.Events.HAS_ALARM, 1);
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
long eventID = Long.parseLong(uri.getLastPathSegment());
Log.wtf("EventID", "" + eventID);
在我的日志中,我得到一个事件ID(例如10)。然后我尝试在以下后立即更新:
values = new ContentValues();
Uri updateUri = null;
values.put(CalendarContract.Events.TITLE, "TESTING");
updateUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventID);
int rows = cr.update(updateUri, values, null, null);
Log.wtf("Update", "Rows updated: " + rows);
我在第int rows = cr.update(updateUri, values, null, null);
行
FATAL EXCEPTION: main
Process: com.innovodynamics.tripplanner, PID: 23267
android.database.sqlite.SQLiteException
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.update(ContentProviderNative.java:568)
at android.content.ContentResolver.update(ContentResolver.java:1362)
at com.innovodynamics.tripplanner.ReminderDialogFragment.writeEvent(ReminderDialogFragment.java:330)
at com.innovodynamics.tripplanner.ReminderDialogFragment.access$600(ReminderDialogFragment.java:43)
at com.innovodynamics.tripplanner.ReminderDialogFragment$11.onClick(ReminderDialogFragment.java:294)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
这里有什么问题?