castor问题

07-11-15 genuin66
我用castor把一对象映射成xml文件,编译通过,但是运行出现异常,请高手指教:

import java.io.*;

import org.exolab.castor.xml.*;

public class Test

{

public static void main(String[] argv) {

FlightBean bean =new FlightBean( );

bean.setCarrier( "AR ");

bean.setNumber(426);

bean.setDepartureTime( "6:23a ");

bean.setArrivalTime( "8:42a ");

try {

File file = new File( "test.xml ");

Writer writer=new FileWriter(file);

Marshaller.marshal(bean, writer);

} catch(Exception e) { }

}

}

class FlightBean implements java.io.Serializable

{

private String m_carrier;

private int m_number;

private String m_departure;

private String m_arrival;

public FlightBean( ) {m_carrier=null;m_number=0;m_departure=null;m_arrival=null;}

public void setCarrier(String carrier) { m_carrier = carrier;}

public String getCarrier() { return m_carrier; }

public void setNumber(int number) { m_number = number; }

public int getNumber() { return m_number; }

public void setDepartureTime(String time) { m_departure = time; }

public String getDepartureTime() { return m_departure; }

public void setArrivalTime(String time) { m_arrival = time; }

public String getArrivalTime() { return m_arrival; }

}

E:\ccc> javac Test.java

E:\ccc> java Test

org.xml.sax.SAXException:

unable to instantiate FlightBean; java.lang.IllegalAccessException:

Class org.exolab.castor.xml.UnmarshalHandler can not access a member of class

FlightBean with modifiers "public " at org.exolab.castor.xml.UnmarshalHandler.startElement(Unknown Source)

banq
2007-11-15 10:20
将class FlightBean 前面加public

猜你喜欢