JAXB给我:java.lang.IllegalArgumentException:is参数不得为空

2022-09-02 10:01:00

我正在使用JAXB将一些XML解构到Java对象中来执行此操作:

我的代码看起来有点像这样:

InputStream testMsg = getClass().getResourceAsStream("TestDocumentEvent.xml");
Unmarshaller unmarshaller = JAXBContext.newInstance(DocumentEvent.class).createUnmarshaller();
DocumentEvent unmarshalled = (DocumentEvent) unmarshaller.unmarshal(testMsg);

但是,当我运行此代码时,我得到一个异常:

java.lang.IllegalArgumentException: is parameter must not be null

这是怎么回事?


答案 1

这是因为您正在传递给unmarshaller('is'参数,geddit)为空,请检查资源名称是否正确。InputStream


答案 2

推荐