0
請給我這個錯誤,我不明白。java.lang.IllegalArgumentException:錯誤的類:類java.lang.String?
這是代碼:
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)
發佈完整的logcat輸出。 –
哪一行出現錯誤? – Keale
它看起來像在光標的第三列中有一個字符串。你想做什麼?從String日期轉換爲String日期? – Juangcg