public class helloworld implements Runnable
{ public int test = 3;

public int zz = 99;

public void setTest(int atest)
{
this.test =  atest;
}

public static void main(String [] arg)
{
System.out.println("hello");
}

public void run()
{
System.out.println(" 运行开始"); } 
}
/********************/
  try{
              helloworld p = new helloworld();
              p.setTest(111);
              System.out.println(p.test);
              
              FileOutputStream os = new FileOutputStream("fileformat/cust.xml");
              XMLEncoder encoder = new XMLEncoder(os);
              encoder.writeObject(p);
              encoder.close();    }
  catch (Exception e)
  {
  
  }
/***********/
得到的cust.xml是这样子地
<?xml version="1.0" encoding="UTF-8"?> 
<java version="1.4.2" class="java.beans.XMLDecoder"> 
 <object class="fileformat.helloworld"/> 
</java> 
为什么没有test 和zz这两个成员变量一起添加进来呢?

解决方案 »

  1.   

    public class helloworld implements Runnable还需要实现 
    public class helloworld implements Runnable,java.io.serialize
      

  2.   

    我改成了这个样子,可是还是不行呢~~
    生成的xml文件还是上面的那个东东,大哥们帮帮忙啊public class helloworld implements  Serializable
    {
    private static final long serialVersionUID = 616434644208950152L;

    public int test = 3;

    public int zz = 99;

    public void setTest(int atest)
    {
    this.test =  atest;
    }

    public int getNum()
    {
    return this.test;
    }
    public void set()
    {

    }

    public  helloworld()
    {

    }
    public String toString()
    {
    return "";
    } public static void main(String [] arg)
    {
    System.out.println("hello");
    }

    public void run()
    {
    System.out.println(" 运行开始"); } 
    }
      

  3.   

    呵呵,知道为什么了,要定义set和get等方法