Need help with XMLEncoder
Hello,
I'm new to XMLEncoder and trying to grasp it's basics.
This works fine:
###############################################################
import java.beans.*;
import java.io.*;
public class TestIntegrated
{
private int value;
public TestIntegrated(){
value = 0;
}
public int getValue(){ return value; }
public void setValue(int value){ this.value = value; }
public static void main(String[] args)
throws FileNotFoundException{
TestIntegrated t = new TestIntegrated();
t.setValue(5);
XMLEncoder e = new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream("Test.xml"))
);
e.writeObject(t);
e.close();
}
}
###############################################################
If I split this in two Classes, it won't work anymore.
The error message is:
java.lang.IllegalAccessException: Class sun.reflect.misc.Trampoline
can not access a member of class Test with modifiers "public"
Continuing ...
java.lang.Exception: XMLEncoder:
discarding statement XMLEncoder.writeObject(Test);
Continuing ...
code:
###############################################################
import java.io.*;
class Test implements Serializable{
private int value;
public Test(){
value = 0;
}
public int getValue(){ return value; }
public void setValue(int value){ this.value = value; }
}
###############################################################
import java.beans.*;
import java.io.*;
public class TestMain
{
public static void main(String[] args) throws FileNotFoundException{
Test t = new Test();
t.setValue(5);
XMLEncoder e = new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream("Test.xml"))
);
e.writeObject(t);
e.close();
}
}
################################################################
Any Ideas why this won't work? I'm using java version 1.5.0_09.
Thanks, Manuel Kasten