0

Please I get this error that I do not understand.

This is the code:

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

This is the 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
  • Post your full logcat output. Commented Aug 30, 2013 at 8:19
  • which line does the error appear? Commented Aug 30, 2013 at 8:19
  • 1
    It looks like there is a string in the third column of the cursor. What are you trying to do? Convert from a String date to a String date? Commented Aug 30, 2013 at 8:22
  • @I am trying to format the date... :-( Commented Aug 30, 2013 at 8:46

1 Answer 1

2

Read the API Guide on Calendar Provider to know about accessing the calendar events.

The mistakes you are making are:

  • Do not use hard coded string literals ("dtstart", ..); use the constants defined in CalendarContract.EventsColumns for the column names.
  • The DTSTART and DTEND columns contain the start and end time in long format (milliseconds since epoch).
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.