标签: xmlencoder

使用 XMLEncoder 时出现 java.lang.Instantiation 异常

我试图在我的 Java 程序中使用 XMLEncoder,但我收到了 java.lang.InstantiationException。以下是我正在使用的代码:

   /*
       Method for serialization.
   */
   public void serializeToXml(Object obj) throws FileNotFoundException{

        FileOutputStream fos = new FileOutputStream("/home/neeraj/xmlOP.xml"); 
        XMLEncoder encoder  =  new XMLEncoder(fos);
        encoder.writeObject(obj);
        encoder.close();
    }


   public static void main(String [] args){


        String uuid = UUID.randomUUID().toString();

        SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy");
        Date date = new Date();
        String tDate = format.format(date);

        ClassA a = new  ClassA(uuid,"expense","Pune",tDate,1,200,0,4);
        a.createAssociatedEvents(2);

        serializationExample serializer = new serializationExample();
        try {

            serializer.serializeToXml(a);

        } catch (FileNotFoundException e) {

            e.printStackTrace();
        }

}
Run Code Online (Sandbox Code Playgroud)

除此之外:我还有两个类:classA 和 classB。这两个类都实现了 Serializable。ClassA 有一个 …

java exception xmlencoder instantiationexception

2
推荐指数
1
解决办法
6795
查看次数