0

请我收到这个我不明白的错误。

这是代码:

Cursor cursor = context.getContentResolver()
            .query(Uri.parse("content://com.android.calendar/events"),
                    new String[] { "calendar_id", "title", "description",
                            "dtstart", "dtend", "eventLocation","allDay" }, null,
                    null, null);
    cursor.moveToFirst();
    // fetching calendars name
    String CNames[] = new String[cursor.getCount()];

    for (int i = 0; i < CNames.length; i++) {

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
        String day =df.format(cursor.getString(3));

这是 LogCat:

08-30 10:07:09.560: E/AndroidRuntime(5008): FATAL EXCEPTION: main
08-30 10:07:09.560: E/AndroidRuntime(5008): java.lang.IllegalArgumentException: Bad     class: class java.lang.String
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     java.text.DateFormat.format(DateFormat.java:296)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     java.text.Format.format(Format.java:93)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     com.examples.android.calendar.Utility.readCalendarEvent(Utility.java:46)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     com.examples.android.calendar.CalendarView$1.run(CalendarView.java:185)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     android.os.Handler.handleCallback(Handler.java:730)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     android.os.Handler.dispatchMessage(Handler.java:92)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     android.os.Looper.loop(Looper.java:137)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     android.app.ActivityThread.main(ActivityThread.java:5103)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     java.lang.reflect.Method.invokeNative(Native Method)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     java.lang.reflect.Method.invoke(Method.java:525)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-30 10:07:09.560: E/AndroidRuntime(5008):     at     dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

2

阅读Calendar Provider上的 API 指南,了解如何访问日历事件。

你犯的错误是:

  • 不要使用硬编码的字符串文字(“dtstart”,..);使用CalendarContract.EventsColumns为列名定义的常量。
  • DTSTARTDTEND列包含long格式的开始和结束时间(自纪元以来的毫秒数)。
于 2013-08-30T08:35:38.400 回答