E
ebby83
I am trying to read write <Event> objects to an ArrayList ... but when
I try to convert the arraylist back to the object arrayit gives me a
ClassCastException for the line
return (Event[]) a.toArray();
--------------------------------------
BufferedReader ois = null;
ArrayList<Event> a = new ArrayList<Event>();
try {
ois = new BufferedReader(new FileReader(this.calFile));
Event e = null;
String line;
while ((line = ois.readLine()) != null) {
e = new Event(line);
a.add(e);
}
ois.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (InvalidTimeRangeException e) {
e.printStackTrace();
}
if (a.isEmpty())
return null;
return (Event[]) a.toArray();
I try to convert the arraylist back to the object arrayit gives me a
ClassCastException for the line
return (Event[]) a.toArray();
--------------------------------------
BufferedReader ois = null;
ArrayList<Event> a = new ArrayList<Event>();
try {
ois = new BufferedReader(new FileReader(this.calFile));
Event e = null;
String line;
while ((line = ois.readLine()) != null) {
e = new Event(line);
a.add(e);
}
ois.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (InvalidTimeRangeException e) {
e.printStackTrace();
}
if (a.isEmpty())
return null;
return (Event[]) a.toArray();