1
I am writing a code that reads data from an XML returned by equipment, but some TAG
now it has now it does not and I cannot verify the existence of the same.
Follow the code used to read XML and use the data.
public void lerXml(String xml) {
String xmlFilePathNFe3 = xml;
JAXBContext context = null;
CFe cfe = null;
try {
context = JAXBContext.newInstance(CFe.class.getPackage().getName());
Unmarshaller unmarshaller1 = context.createUnmarshaller();
cfe = (CFe) unmarshaller1.unmarshal(new File(xmlFilePathNFe3));
} catch (JAXBException ex) {
ex.printStackTrace();
}
String exemploCpf = cfe.getInfCFe().getDest().getCPF();
.....
But if the TAG
<CPF>
no exist returns exception Nullpointer
how to check if there is the relevant information.
Nullpointer happens in unmarshal or getCPF()?
– Fagner Fonseca
Yes Nullpointer occurs when I try to assign the value within getCPF() to an object, and this getCPF() does not exist in that XML.
– DevAgil