using parameterized ArrayList

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top