简体   繁体   中英

Java XML Null Pointer Exception

I have a very large XML File (around 29 GB)where every other alternate line is a XML with around 500 attributes. I am reading the file sequentially and sending out the line to unmarshaller which creates a object out of it.

I got the following exception after some time.

java.lang.NullPointerException  at com.sun.xml.internal.stream.Entity$ScannedEntity.close(Entity.java:439)

The following accepts the line and unmarshalls it.

sCurrentLine = br.readLine();
idDetails = IDUnmarshal.IDUnmarshall(sCurrentLine);
idObjectList.add(idDetails);

This is the full stack trace

     java.lang.NullPointerException at com.sun.xml.internal.stream.Entity$ScannedEntity.close(Entity.java:439)
     at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.endEntity(XMLEntityManager.java:1404)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)

            at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
            at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
            at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
            at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
            at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
            at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
            at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
            at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
            at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
            at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
            at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)

Have you considered that you may be reading a line that doesn't exist with your .readLine(); call and thus storing within it a null value which is being used by the TDUnmarshall method and throwing the error?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM