Thanks Allan!

So I made CincoModel public, and now it works. Is there any disadvantage to
this aproach, is it better to provide my own no-arg constructor and not make
my class public? Thanks again.

-----Original Message-----
From: Allan MacKinnon [mailto:[EMAIL PROTECTED]]
Sent: Friday, March 16, 2001 11:44 AM
To: Josh Howe
Subject: Re: Externalizable problem



you need a public no-arg constructor.  if you don't make class
CincoModel public it and its automatically created no-arg
constructor (I'm assuming you didn't write one) have package
access.



Josh Howe wrote:
>
> Hi all,
>
> Sorry for the cross-post from Java - General, but I wasn't getting help
> there.
>
> I hope somebody can help me with my problem. I am trying to save an object
> to disk by implementing Extenalizable. Here's the code:
>
> class CincoModel implements Externalizable{
>         private Vector letterstates = new Vector(52);
>         private ModelProxy proxy;
>
>             ...methods...
>
>         public void writeExternal(ObjectOutput out) throws IOException {
>                 out.writeObject(letterstates);
>         }
>
>         public void readExternal(ObjectInput in) throws IOException,
> ClassNotFoundException {
>                 letterstates = (Vector)in.readObject();
>         }
> }
>
> Here's the class that saves and loads the object:
>
> class Cinco2 extends JFrame{
>
>         ...methods...
>
>         private void saveGame(){
>                 CincoModel m = proxy.getModel();
>                 if (m != null){
>                         try{
>                                 FileOutputStream ostream = new
> FileOutputStream("t.tmp");
>                                 ObjectOutputStream p = new
> ObjectOutputStream(ostream);
>
>                                 p.writeObject(m);
>
>                                 p.flush();
>                                 ostream.close();
>                         } catch (IOException ioe) {
>                                 System.out.println ("Error saving file:");
>                                 System.out.println (ioe.getMessage());
>                         }
>                 }
>         }
>
>         private void loadGame(){
>                 try{
>                         FileInputStream instream = new
> FileInputStream("t.tmp");
>                         ObjectInputStream p = new
> ObjectInputStream(instream);
>
>                         CincoModel m = (CincoModel)p.readObject();
>                         proxy.setModel(m);
>
>                         instream.close();
>                 } catch (Exception e) {
>                         System.out.println ("Error loading file:");
>                         System.out.println (e.getMessage());
>                 }
>         }
>
> When the loadGame() method fires, I get the following exception:
>
> CincoModel; IllegalAccessException
>
> Does anybody know why I'm getting this error? Thanks!
>
> ----------------<< "[EMAIL PROTECTED]" FOOTER MESSAGE >>---------------------
>
> To leave list [EMAIL PROTECTED], please direct the one-line message
>         unsubscribe JAVA
> to email address
>         [EMAIL PROTECTED]
> If you have difficulties unsubscribing, please direct email to
>         [EMAIL PROTECTED]
>
>                     York University, Toronto  Canada
>                            http://www.yorku.ca
>
> _______________________________________________
> Swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/swing

--
Allan MacKinnon
[EMAIL PROTECTED]
Boston, MA

_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to