0

I researched this error over the internet. I find out reason why this error cause me. But in my particular case it is different. I don't know how to fix it.

Our system exports some xml every particular time. So I think when it generating, my program is working exact that time then it cause this error.

How can I fix this problem?

FileInputStream fis=null;
File fXmlFile = new File(file);             
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); 
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
dBuilder.setErrorHandler(new ErrorHandler() {    
    @Override
    public void warning(SAXParseException exception) throws SAXException {
        System.err.println("warning: caught exception");
        exception.printStackTrace(System.err);
    }

    @Override
    public void fatalError(SAXParseException exception) throws SAXException {
        System.err.println("fatalError: caught exception");
        exception.printStackTrace(System.err);
    }

    @Override
    public void error(SAXParseException exception) throws SAXException {
        System.err.println("error: caught exception");
        exception.printStackTrace(System.err);
    }
});
fis = new FileInputStream(fXmlFile);
org.w3c.dom.Document doc = dBuilder.parse(fis);
fis.close();
doc.getDocumentElement().normalize();           
return doc;

fatalError: caught exception org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)

phil652
  • 1,484
  • 1
  • 23
  • 48
Nergui
  • 1
  • 1
  • 2
  • When it is generating some xml from our system. it was empty or broken. – Nergui Mar 09 '15 at 17:10
  • 1
    Well it sounds like the file is indeed empty - which would give exactly this error. So really, the question is why it's empty... and we can't help you answer that with the information you've given us. – Jon Skeet Mar 09 '15 at 17:14

0 Answers0