Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

serialized ArrayList object  RSS feed

 
pradeepta chopra
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 ]
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor 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
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!