java.io.NotSerializableException: paint.Main$1

hi everybody this is my problem...

i have this code:

public class Main extends JFrame

{

class figura implements Serializable

{

Point x, y;

int tipo;

int rettipo(){ return tipo;}

public Point retx(){ return x;}

public Point rety(){ return y;}

void ponertipo(int a){ tipo = a; }

void ponerpx(Point a){ x = a; }

void ponery(Point a){ y = a;}

};

JFileChooser archivos = new JFileChooser();

Vector almacen = new Vector(1);

figura temp = new figura();

.... //more code....

i wanna save temp object in a file...

....//more code before this...

archivos.showSaveDialog(Main.this);

File archivo;

FileOutputStream archivo2 = null;

ObjectOutputStream obj = null;

archivo = archivos.getSelectedFile();

try{

archivo2 = new FileOutputStream(archivo.getAbsolutePath());

obj = new ObjectOutputStream(archivo2);

obj.writeObject(temp);

obj.close();

}

catch(Exception ex)

{

Throwable tro;

ex.printStackTrace();

tro=ex.getCause();

tro.getMessage();

}

...

and this is what i got:

java.io.NotSerializableException: paint.Main$1

..

..

and this:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

...

..

Any ideas?

[1403 byte] By [eckoa] at [2007-11-27 0:10:45]
# 1
The inner class has a hidden reference to the outer class, which in turn has a reference to an anonymous class which isn't serializable.Make the named inner class static.
ejpa at 2007-7-11 16:12:28 > top of Java-index,Core,Core APIs...
# 2

hi that solved my problem, but i still have questions....

why with static the problem is solved? i understand that static makes that all instance of the class will share the same values of their attributes, if i set x = 9 all the instance of the class will have 9 in x :S. i was trying to make several objects of that class that keeps information about geometric figures drawed in a panel, those figures inside a vector object then save the vector with serialization, but if the class is static i wont be able to save more than one figure. am i right? what can i do...

eckoa at 2007-7-11 16:12:28 > top of Java-index,Core,Core APIs...
# 3

> why with static the problem is solved?

Because a static nested class doesn't have a hidden reference to the outer object.

> i understand

> that static makes that all instance of the class will

> share the same values of their attributes

No it doesn't. It just means the above, and also that the class doesn't have access to instance data members of the enclosing class.

> if the class is static i wont be able to save more

> than one figure. am i right?

No you're not, see above.

ejpa at 2007-7-11 16:12:28 > top of Java-index,Core,Core APIs...
# 4
thanks! it works! now the problem is than when i read the figures objects and use their information to draw on a panel figures as a paint program, it draws the figures but suddenly it erase them too :S. i guess i have to ask this on swing forum
eckoa at 2007-7-11 16:12:28 > top of Java-index,Core,Core APIs...