Why am I getting this error Premature end of file?

后端 未结 7 2049
滥情空心
滥情空心 2020-12-16 10:40

I am trying to parse an XML response, but I am failing miserably. I thought initially that the xml was just not being returned in the response, so

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 11:26

    I came across the same error, and could easily find what was the problem by logging the exception:

    documentBuilder.setErrorHandler(new ErrorHandler() {
        @Override
        public void warning(SAXParseException exception) throws SAXException {
            log.warn(exception.getMessage());
        }
    
        @Override
        public void fatalError(SAXParseException exception) throws SAXException {
            log.error("Fatal error ", exception);
        }
    
        @Override
        public void error(SAXParseException exception) throws SAXException {
            log.error("Exception ", exception);
        }
    });
    

    Or, instead of logging the error, you can throw it and catch it where you handle the entries, so you can print the entry itself to get a better indication on the error.

提交回复
热议问题