• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problems reading an object file

 
Micah Wedemeyer
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I keep getting the same exceptions when I attempt to read an object file.
If I'm correctly reading the stack trace, I'm getting an InvalidClassException followed by an IllegalAccessException. I don't know anything about either one.
I'm trying to write a List (an ArrayList) to a file, then read it back in. I write it as a List and attempt to read it (cast) as a List. If anyone has any ideas, please let me know.
Micah
java.io.InvalidClassException: com.sun.java.util.collections.AbstractList; IllegalAccessException
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java)
at com.dailyiowan.ontheline.OnTheLine.readChoiceList(OnTheLine.java)
at com.dailyiowan.ontheline.OnTheLine.doPost(OnTheLine.java)
at com.dailyiowan.ontheline.OnTheLine.doGet(OnTheLine.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:516)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:611)
at com.livesoftware.jrun.JRun.runServlet(JRun.java)
at com.livesoftware.jrun.JRunGeneric.handleConnection(JRunGeneric.java)
at com.livesoftware.jrunwebstar.JRunWebStar.HandleConnection(JRunWebStar.java)
 
Micah Wedemeyer
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HA HA, I noticed I am a now ranch hand. More like an outstretched hand begging to be saved!
 
Micah Wedemeyer
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anybody? Got any ideas?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the code?
 
Micah Wedemeyer
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've decided not to mess around with writing the List. This seems to be the main problem. Instead, I'll try writing each element of the list to a file. When I read them back in, I'll reconstruct the list manually. Just to make sure, how do I read all objects in a file? Is it like this?
<code>
ObjectInputStream in = new ObjectInputStream(new FileInputStream("filename"));
Object o;
List a = new ArrayList();
while (o = in.readObject())
a.add(o);
</code>
I'm assuming, of course, that when it hits EOF then readObject will return null. Is this a valid assumption?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic