我正在尝试使用该类将具有 INetAddress 类型成员的对象编码为 xml java.beans.XMLEncoder
。不幸的是,我得到以下异常:
java.lang.IllegalAccessException:类 sun.reflect.misc.Trampoline 无法访问带有修饰符“”的类 java.net.Inet4Address 的成员
这是我的代码:
public class INetAddressFoo {
private InetAddress addr;
public INetAddressFoo() {
}
public InetAddress getAddr() {
return addr;
}
public void setAddr(InetAddress addr) {
this.addr = addr;
}
}
public class Test{
public static void main() throws Exception {
INetAddressFoo foo = new INetAddressFoo();
InetAddress addr = InetAddress.getByName("localhost");
foo.setAddr(addr);
File file = new File("inet.xml");
XMLEncoder encoder = null;
try {
encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(file)));
encoder.writeObject(t);
} finally {
if (encoder != null) {
encoder.close();
}
}
}
}