Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2007

Tip: Looking for answers? Try searching our database.

Need help with XMLEncoder

Thread view: 
Manuel Kasten - 05 Jan 2007 17:43 GMT
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
Andrew Thompson - 05 Jan 2007 18:03 GMT
> java.lang.IllegalAccessException: Class sun.reflect.misc.Trampoline
> can not access a member of class Test with modifiers "public"
...
> class Test implements Serializable{

 public class Test implements Serializable{

> Any Ideas why this won't work? ...

Just a WAG.

Andrew T.
Manuel Kasten - 06 Jan 2007 01:56 GMT
Andrew Thompson schrieb:

>> java.lang.IllegalAccessException: Class sun.reflect.misc.Trampoline
>> can not access a member of class Test with modifiers "public"
[quoted text clipped - 8 lines]
>
> Andrew T.

Of course. Was obvious the moment I saw it.
Thank you very much, works now.

Manuel Kasten


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.