0

jaxb.index file but i don´t know if it´s a good way to me.

I have a structure of classes and packages thats represent the tree of xml that i want to extract his date.

So i want to know what´s the best way, because i´m getting nullPointerException when i´m trying to acess a field.

So what can i do?

My root class is NFeProc.

enter image description here

My main class

public class Teste {

    public static void main(String[] args) {

        try {
            JAXBContext jaxbContext = JAXBContext.newInstance(new Class[] { nfeProc.NFeProc.class });
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            NFeProc nFeProc = (NFeProc) unmarshaller.unmarshal(new File("nfe.xml"));
            nFeProc.getNfe().getInfNFe().getEmitente().getCnpj();
        } catch (JAXBException e) {
            e.printStackTrace();
        }
    }

}
4

1 回答 1

0

看起来好像您正在调用get的从 unmarshal 方法返回的对象之一是 null。如果它可以为空,则需要在调用 get 之前检查它。如果它不应该为空,则映射可能是错误的。

于 2013-09-06T11:10:38.997 回答