我使用XOM收到致命错误:“[致命错误]:1:1:文件过早结束。”

时间:2013-10-27 03:29:20

标签: java xml eclipse xom

我似乎没有制作重复的帖子,所以这里有详细信息......

当我使用XOM(XML对象模型,Java库)中的非静态方法Builder.build()解析文档时,在Eclipse控制台中我得到:

[Fatal Error] :1:1: Premature end of file.

这是一个严重的问题,强行停止程序的运行。

我正在使用的方法的内容如下......

public boolean buildDocument() {

    boolean out = true;
    Builder b = null;
    b = new Builder();

    String xml = "";
    String newXml = "";
    StringBuilder xmlSb = new StringBuilder();
    URL xmlUrl = null;
    try {
        xmlUrl = new URL(this.packAddr);
    } catch (MalformedURLException e1) {
        Pcdl.log.severe(e1.getMessage());
        out = false;
    }

    InputStream is;
    try {

        is = xmlUrl.openStream();
        while (is.available() > 0) {
            xmlSb.append(is.read());
        }

    } catch (IOException e1) {
        e1.printStackTrace();
        Pcdl.log.severe(e1.getMessage());
        out = false;
    }

    xml = xmlSb.toString();

    // Add more lines if needed.  I hope that nobody actually had to use any XML entities.
    newXml = Util.removeUTF8BOM(xml)
            .replace("&", "&")
            ;

    Pcdl.log.info("XML Data Size: " + newXml.length() + " B.");
    System.out.println(newXml);

    // Actually build it.
    try {
        this.doc = b.build(new ByteArrayInputStream(newXml.getBytes("UTF-8")));
    } catch (ParsingException | IOException e) {
        Pcdl.log.severe("Document build error: " + e.getMessage());
        System.out.println(e.getMessage());
        out = false;
    }

    System.out.println(this.doc);
    return out;

}

我将整个程序放在GitHub存储库中:“http://github.com/Treyzania/PraseocraftDL/”。如果您希望以任何方式为该项目做出贡献,请做!只要做一个叉子,我就会看到它里面有什么。

此方法来自“com.treyzania.praseocraft.ftb.downloader.PackFile”。 我知道我的包名很长,但现在改变它们为时已晚。我正在开发的项目是一个获取XML文档的程序(例如:http://pastebin.com/raw.php?i=B42in4c5),并将其编译为%appdata%/。mc-pcdl / packs /(或类似)中的Minecraft modpack,并编辑一些其他文件,以便使用Minecraft Launcher正确注册数据。我试图让这个项目尽可能抽象,所以看起来可能有更多的类而不是必要的。我也在尽我所能来解决这个问题。没有人在工作。

1 个答案:

答案 0 :(得分:0)

Treyzania解决了他的问题:

  

我不得不施展

xmlSb.append(is.read());
     

作为

xmlSb.append((char) is.read());
     

解决问题。但是,我现在使用不同的方法下载文件,在我的项目的这一部分不再有任何问题。