如何解决文件异常Java过早结束

时间:2016-02-11 03:34:22

标签: java xml parsing

我不确定发生了什么,这让我疯了!

org.xml.sax.SAXParseException;提前结束。

问题似乎在于这种方法,我已经标记了可疑代码的行:

public static Object execXPath1(String xml, String xPath, QName type) {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    logger.info("Inside execXPath method");
    try {
        logger.debug("Inside try block");
        DocumentBuilder builder = factory.newDocumentBuilder();
        logger.info("Created DocumentBuilder object");

        logger.debug("XML:\n"+xml);

        //problem is here
        Document doc = builder.parse(new InputSource(new StringReader(xml)));

        logger.debug("Calling execXPath (3 param)");
        return execXPath2(doc, xPath, type);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

它是一个标准的DOM解析器,xml应该是好的。任何帮助或建议将不胜感激

这是我的堆栈跟踪:

[Fatal Error] :-1:-1: Premature end of file.
org.xml.sax.SAXParseException; Premature end of file.
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)generalatomics
    at com.generalatomics.taxengine.automation.calc.PayrollErrorTest.execXPath1(PayrollErrorTest.java:156)
    at com.generalatomics.taxengine.automation.calc.PayrollErrorTest.execXPathForValue1(PayrollErrorTest.java:135)
    at com.generalatomics.taxengine.automation.calc.PayrollErrorTest.getValueForInput(PayrollErrorTest.java:129)
    at com.generalatomics.taxengine.automation.calc.PayrollErrorTest.testTKEErrors(PayrollErrorTest.java:82)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:696)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:882)
    at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:75)
    at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:14)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

0 个答案:

没有答案