IllegalAccessException while Unserializing

Put your problem here if it does not fit any of the other categories.

IllegalAccessException while Unserializing

Postby dgouveia » Wed Feb 23, 2011 12:30 pm


I'm having problems serializing/unserializing objects in Android.

It seems that serializing the object is OK, but when I try to unserialize it, an IllegalAccessException is raised.

This is the code to serialize the object:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void saveList(){
  2.         try{
  3.         FileOutputStream f_out = new FileOutputStream("application.dat");
  4.         ObjectOutputStream obj_out = new ObjectOutputStream (f_out);
  5.         obj_out.writeObject ( dataAdapter );
  6.         f_out.close();
  7.         }catch(Exception e){Toast.makeText(context, "Could not save list.", Toast.LENGTH_LONG).show();}
  8.     }
Parsed in 0.017 seconds, using GeSHi

And this is the code used to unserialize the object:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  private void loadList(){
  2.         try{
  3.         FileInputStream f_in = new FileInputStream("application.dat");
  4.         ObjectInputStream obj_in = new ObjectInputStream (f_in);
  5.         dataAdapter = (PlayerAdapter) obj_in.readObject();
  6.         dataAdapter.notifyDataSetChanged();
  7.         f_in.close();
  8.         }catch(Exception e){Toast.makeText(context, "Unable to load list.\n" + e.getMessage(), Toast.LENGTH_LONG).show();}
  9.     }
Parsed in 0.010 seconds, using GeSHi

PlayerAdapter is a custom ArrayAdapter used to handle a ListView's items.
dataAdapter is the PlayerAdapter's instance used in my ListView.

What am I doing wrong?

Thanks :)
Posts: 6
Joined: Sat Jan 29, 2011 5:25 pm


Re: IllegalAccessException while Unserializing

Postby Mardaneus » Wed Feb 23, 2011 5:33 pm

Could you post the code for the PlayerAdapter class? There might be a problem there, because the saveList and loadList methods are fine at first sight.

One possibility is that the PlayerAdapter class contains final fields.
Junior Developer
Junior Developer
Posts: 14
Joined: Mon Feb 14, 2011 10:30 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 8 guests