我得到錯誤,而運行這段代碼... 這裏是我的代碼:值插入谷歌日曆
alendar cal = Calendar.getInstance();
Uri EVENTS_URI = Uri.parse(getCalendarUriBase(this) + "events");
ContentResolver cr = getContentResolver();
// event insert
ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", edSubject.getText().toString());
values.put("allDay", 0);
values.put("dtstart", dateStart.toString()); // event starts at 11 minutes from now
values.put("dtend", cal.getTimeInMillis()+60*60*1000); // ends 60 minutes from now
values.put("description", "Reminder description");
values.put("visibility", 0);
values.put("hasAlarm", 1);
Uri event = cr.insert(EVENTS_URI, values);
// reminder insert
/*Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(this) + "reminders");
values = new ContentValues();
values.put("event_id", Long.parseLong(event.getLastPathSegment()));
values.put("method", 1);
values.put("minutes", 10);
cr.insert(REMINDERS_URI, values);*/
private String getCalendarUriBase(ActivityAppointment act) {
String calendarUriBase = null;
Uri calendars = Uri.parse("content://calendar/calendars");
Cursor managedCursor = null;
try {
managedCursor = act.managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
}
if (managedCursor != null) {
calendarUriBase = "content://calendar/";
} else {
calendars = Uri.parse("content://com.android.calendar/calendars");
try {
managedCursor = act.managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
}
if (managedCursor != null) {
calendarUriBase = "content://com.android.calendar/";
}
}
return calendarUriBase;
}
的logcat:
01-16 15:34:27.620: E/AndroidRuntime(3114): FATAL EXCEPTION: main
01-16 15:34:27.620: E/AndroidRuntime(3114): java.lang.NullPointerException
01-16 15:34:27.620: E/AndroidRuntime(3114): at android.os.Parcel.readException(Parcel.java:1327)
01-16 15:34:27.620: E/AndroidRuntime(3114): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:182)
01-16 15:34:27.620: E/AndroidRuntime(3114): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
01-16 15:34:27.620: E/AndroidRuntime(3114): at android.content.ContentProviderProxy.insert(ContentProviderNative.java:447)
01-16 15:34:27.620: E/AndroidRuntime(3114): at android.content.ContentResolver.insert(ContentResolver.java:721)
01-16 15:34:27.620: E/AndroidRuntime(3114): at com.sree.weekdayview.calendar.activities.ActivityAppointment.SaveData(ActivityAppointment.java:348)
01-16 15:34:27.620: E/AndroidRuntime(3114): at com.sree.weekdayview.calendar.activities.ActivityAppointment$3.onClick(ActivityAppointment.java:117)
01-16 15:34:27.620: E/AndroidRuntime(3114): at android.view.View.performClick(View.java:3122)
您可以修復此錯誤?這與我一樣,但只有Android 2.3.4薑餅..:/ –