jjzjj

java - eclipse : XML document structures must start and end within the same entity 中的 SaxParseException

coder 2024-03-14 原文

我正在使用 JAVA 的 last.fm API,可以找到 here .

我有一个巨大的Dataset其中我只使用包含用户艺术家历史和播放的文件。我用 Java 编写了一段代码,它提取这些艺术家姓名并根据 Artist.getSimilar() 方法返回相似的艺术家。

我运行了一次,但不是为所有艺术家运行的。我中途终止了调试。然而下一次,我的结果从缓存中返回,请求不再发送到网络服务器。问题是,这次我只得到结果,直到我终止结果的艺术家。我尝试对 artists=Artist.getTopAlbums() 使用另一种方法,我中途终止并在下次遇到同样的问题。我得到的错误是:

[Fatal Error] :513:9: <strong>XML document structures must start and end within the same entity.</strong>
Exception in thread "main" de.umass.lastfm.CallException: org.xml.sax.SAXParseException; lineNumber: 513; columnNumber: 9; XML document structures must start and end within the same entity.
Caused by: org.xml.sax.SAXParseException; lineNumber: 513; columnNumber: 9; XML document structures must start and end within the same entity.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:251)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300)

和一堆其他的异常(exception)情况,这不是这里的重要部分。

我尝试重新安装 eclipse,以 -clean 模式启动 eclipse 并清理工作区。没有任何效果。我也创建了一个新的工作区,但缓存不断返回。我正在使用 Eclipse 3.8。也许在 Eclipse 中清除缓存的有效方法会有所帮助?我该怎么做。似乎没有任何效果。 (也没有像许多文章中建议的那样在 Window>Preferences 中手动清理缓存的选项)。

或者我需要做其他事情吗?任何帮助深表感谢。提前致谢。

我的 java 代码(运行良好,没有错误):

//in main
BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));
String sinput=inp.readLine();
System.out.println(sinput+"\t \t \t"+getSimilarartists(sinput));


//to fetch similar artists
public static StringBuilder getSimilarartists(String artist){
String key = "af2bfbcb4dd49870fdb8e92f128f4ff7";
StringBuilder sb = new StringBuilder();
String art=(Artist.getSimilar(artist, key)).toString();
int i=0;
while(i<art.length()-5){
    if((art.substring(i, (i+4))).equalsIgnoreCase("name")){
        i=i+6;

        while(art.charAt(i)!='\''){
            sb.append(art.charAt(i));
            i++;
        }

        break;
    }
    i++;
}
return sb;
}  

输出(仅最后几行):

hans zimmer;     I recommend=Hans Zimmer & James Newton Howard<br>
nelly furtado;   I recommend=Jennifer Lopez<br>
madonna;     I recommend=Kylie Minogue<br>
blink-182;   I recommend=Box Car Racer<br>
dave gahan;  I recommend=Depeche Mode<br>
kelly clarkson;  I recommend=Carrie Underwood<br>
lucie silvas;    I recommend=Delta Goodrem<br>
natalie imbruglia;   I recommend=Melanie C<br>
michelle branch;     I recommend=The Wreckers<br>
delta goodrem;   I recommend=Ricki-Lee<br>
new order;   I recommend=Electronic<br>
seal;    I recommend=Simply Red<br>
atomic kitten;   I recommend=Liberty X 

 *** (this is where I had terminated my previous run) ***

[Fatal Error] :513:9: XML document structures must start and end within the same entity.<br>
Exception in thread "main" de.umass.lastfm.CallException: org.xml.sax.SAXParseException; lineNumber: 513; columnNumber: 9; XML document structures must start and end within the same entity.
    at de.umass.lastfm.Caller.call(Caller.java:268)<br>
    at de.umass.lastfm.Caller.call(Caller.java:189)<br>
    at de.umass.lastfm.Caller.call(Caller.java:185)<br>
    at de.umass.lastfm.Artist.getSimilar(Artist.java:144)<br>
    at de.umass.lastfm.Artist.getSimilar(Artist.java:132)<br>
    at Recommender.getSimilarartists(Recommender.java:89)<br>
    at Recommender.main(Recommender.java:58)<br>
Caused by: org.xml.sax.SAXParseException; lineNumber: 513; columnNumber: 9; XML document structures must start and end within the same entity.<br>
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:251)
    at     <br>
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300)<br>
    at de.umass.lastfm.Caller.createResultFromInputStream(Caller.java:324)<br>
    at de.umass.lastfm.Caller.call(Caller.java:256)<br>
    ... 6 more

最佳答案

这样的错误通常表示文档格式不正确:

Caused by: org.xml.sax.SAXParseException; lineNumber: 513; columnNumber: 9; XML document structures must start and end within the same entity. at

您可以做一些事情来调试它:

  1. 将 XML 文档打印到日志中,并通过某种 XML validator 运行它。
  2. 检查以确保没有无效字符(例如 UTF-8 文档中的 UTF-16 字符)

关于java - eclipse : XML document structures must start and end within the same entity 中的 SaxParseException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23156292/

有关java - eclipse : XML document structures must start and end within the same entity 中的 SaxParseException的更多相关文章

随机推荐