用java查询last.fm API

时间:2014-09-01 04:56:55

标签: java xml last.fm

我尝试做的是使用last.fm API和track.getSimiliar查找100首类似的歌曲 - 相信。然后在这100首歌曲中找到10首类似的歌曲。

当我尝试找到10首类似的歌曲时,我在while循环中使用函数调用并迭代返回的集合。这工作到第7次通话然后它出错了。

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Collection;


import de.umass.lastfm.*;

public class question {

    public static void main(String args[]) throws FileNotFoundException {
        Caller.getInstance().setUserAgent("tst");

        String key = "6d1b1a7cbcc442e70b3bffcfb163c9a0"; // this is the key used
                                                            // in the Last.fm
                                                            // API examples
        String user = "dgupta33";   
        PrintStream outFile = new PrintStream(new File("output_trackNames.txt"));
        PrintStream outFile2 = new PrintStream(new File("output_Artist.txt"));

        Collection<Track> tracks = Track.getSimilar("Cher", "Believe", key);
        int num = 1;
        for (Track track : tracks) {
            if (track.getMbid() != "" && num <= 100) {

                outFile.println(track.getName());
                outFile2.println(track.getArtist());
                num++;              

            } else if (num > 100)
                break;
        }
        outFile.close();
        outFile2.close();
    }


}

我得到的错误:

[Fatal Error] :2025:48: XML document structures must start and end within the same entity.
Exception in thread "main" de.umass.lastfm.CallException: org.xml.sax.SAXParseException; lineNumber: 2025; columnNumber: 48; XML document structures must start and end within the same entity.
    at de.umass.lastfm.Caller.call(Caller.java:268)
    at de.umass.lastfm.Caller.call(Caller.java:189)
    at de.umass.lastfm.Track.getSimilar(Track.java:369)
    at initiate.Main.main(Main.java:29)
Caused by: org.xml.sax.SAXParseException; lineNumber: 2025; columnNumber: 48; XML document structures must start and end within the same entity.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
    at de.umass.lastfm.Caller.createResultFromInputStream(Caller.java:324)
    at de.umass.lastfm.Caller.call(Caller.java:256)
    ... 3 more

0 个答案:

没有答案