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();
Marcin Wielgus - 16 Mar 2006 03:50 GMT
> return (Event[]) a.toArray();
try
return (Event[]) a.toArray(new Event[0])
for more info read documentation of toArray(T[])

Signature
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
roy2000@gmail.com - 16 Mar 2006 08:41 GMT
> > return (Event[]) a.toArray();
> >
> try
>
> return (Event[]) a.toArray(new Event[0])
or simply
return a.toArray(new Event[0])
Piotr Kobzda - 16 Mar 2006 09:55 GMT
>>>return (Event[]) a.toArray();
>>
[quoted text clipped - 4 lines]
> or simply
> return a.toArray(new Event[0])
or better:
return a.toArray(new Event[a.size()]);
piotr