我正在創建事件日曆。我此異常java.lang.NumberFormatException: Invalid long: 「null」
java.lang.NumberFormatException:無效的長整型:「null」
Utility.java
public class Utility {
public static ArrayList<String> nameOfEvent = new ArrayList<String>();
public static ArrayList<String> startDates = new ArrayList<String>();
public static ArrayList<String> endDates = new ArrayList<String>();
public static ArrayList<String> descriptions = new ArrayList<String>();
public static ArrayList<String> readCalendarEvent(Context context) {
Cursor cursor = context.getContentResolver()
.query(Uri.parse("content://com.android.calendar/events"),
new String[] { "calendar_id", "title", "description",
"dtstart", "dtend", "eventLocation" }, null,
null, null);
cursor.moveToFirst();
// fetching calendars name
String CNames[] = new String[cursor.getCount()];
// fetching calendars id
nameOfEvent.clear();
startDates.clear();
endDates.clear();
descriptions.clear();
for (int i = 0; i < CNames.length; i++) {
nameOfEvent.add(cursor.getString(1));
startDates.add(getDate(Long.parseLong(cursor.getString(3))));
endDates.add(getDate(Long.parseLong(cursor.getString(4))));
descriptions.add(cursor.getString(2));
CNames[i] = cursor.getString(1);
cursor.moveToNext();
}
return nameOfEvent;
}
public static String getDate(long milliSeconds) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
return formatter.format(calendar.getTime());
}
}
logcat的
E/AndroidRuntime(2990): java.lang.NumberFormatException: Invalid long: "null"
E/AndroidRuntime(2990): at java.lang.Long.invalidLong(Long.java:125)
E/AndroidRuntime(2990): at java.lang.Long.parseLong(Long.java:342)
E/AndroidRuntime(2990): at java.lang.Long.parseLong(Long.java:319)
E/AndroidRuntime(2990): at com.examples.android.calendar.Utility.readCalendarEvent(Utility.java:36)
E/AndroidRuntime(2990): at com.examples.android.calendar.CalendarView$1.run(CalendarView.java:184)
爲什麼即時得到這個?任何人都可以幫助我。非常感謝提前..
您可以上傳的代碼呢? – Vigbyor
您正在將字符串解析爲長整型,並且該字符串爲空。 –
這是你的'Utility.readCalendarEvent()'有問題,而不是'CalendarView' – Aprian