首页 > 解决方案 > 如何解决由 JAXB 语句引起的异常?

问题描述

这是我试图运行的代码,但它目前在这一行抛出异常:

try {
        File file = new File(getFilesDir().getPath() + "/" + name + ".xml");
        JAXBContext jaxbContext = JAXBContext.newInstance(Restaurant.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(r, file);

    } catch (JAXBException e) {
        e.printStackTrace();
    }  

我在这一行抛出了一个异常:

JAXBContext jaxbContext = JAXBContext.newInstance(Restaurant.class);

我将日志复制到 pastebin ( https://pastebin.com/WRjXbub7 )

我正在尝试将对象序列化为 XML 文件。我的代码中没有出现红色标记或任何内容,所以我不知道这里有什么问题。谢谢!

标签: javaandroidxmljaxb

解决方案


推荐阅读