• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

serialized ArrayList object

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i serialised an ArrayList to a file.



but i get an error stating that required array but got an ArrayList.
cant we serailize an arraylist to a file???

[edit]Remove bold tags. CR[/edit]
[ August 02, 2008: Message edited by: Campbell Ritchie ]
 
author
Posts: 23868
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

but i get an error stating that required array but got an ArrayList.
cant we serailize an arraylist to a file???



Is this an runtime error? or a compile time error? Just with a quick eyeball on your code, I see the error.

BTW, just because something doesn't compile, doesn't mean that it can't be done. You have to get it to compile first, before you speculate that something won't work.

Henry
 
Sheriff
Posts: 21866
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ArrayList cannot be accessed as if it were an array. You'll have to retrieve the elements using get(int index) instead, and unless you're using generics you will also have to cast it:

You can also include the generics when casting the read object but you will get a compiler warning that cannot be prevented (only suppressed):

[ August 02, 2008: Message edited by: Rob Prime ]
 
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!