我只是没有正确初始化数组中的AnimeItem,还是因为我将整个html代码作为一个元素进行筛选的方式不遵循项目,标题,链接的层次结构?不确定tbh是否尝试过一些似乎无法提出解决方案的其他事情。
public static void main(String[] args)
{
String HS = "";
RSSReader r = new RSSReader();
AnimeItem[] AI = r.getItems(HS);
for(int i = 0; i < AI.length; i++)
{
System.out.println(AI[i].getENTRY() + ":\n" + AI[i].getTITLE() + "\n" + AI[i].getLINK());
}
}
public AnimeItem[] getItems(String urlAddress){
try
{
URL rssUrl = new URL(urlAddress);
BufferedReader in = new BufferedReader(new InputStreamReader(rssUrl.openStream()));
String line;
int ENTRYNUMBER = 0;
while((line = in.readLine())!=null)
{
if(line.contains("<item>"))
{
ENTRYNUMBER++;
ANIMEITEMS[ENTRYNUMBER].setENTRY(ENTRYNUMBER);
}
if(line.contains("<title>"))
{
int firstPos = line.indexOf("<title>");
String temp = line.substring(firstPos);
temp = temp.replace("<title>", "");
int lastPos = temp.indexOf("</title>");
temp = temp.substring(0, lastPos);
ANIMEITEMS[ENTRYNUMBER].setTITLE(temp);
}
if(line.contains("<link>"))
{
int firstPos = line.indexOf("<link>");
String temp = line.substring(firstPos);
temp = temp.replace("<link>", "");
int lastPos = temp.indexOf("</link>");
temp = temp.substring(0,lastPos);
ANIMEITEMS[ENTRYNUMBER].setLINK(temp);
}
}
in.close();
return ANIMEITEMS;
}catch(MalformedURLException ue)
{
System.out.println("Problem with URL: " + ue);
}catch(IOException ioe)
{
System.out.println("Problem with IO: " + ioe);
}
System.out.println("ISSUE");
return null;
}