我在两个不同的文件中有两个java类(Crawler.java和A2ZurlRead.java)。 在A2ZUrlRead.java里面我有以下内容:
private LinkedList<String> issuesUrlsToVisit; // A queue of issues URLs to
// visit
...
public A2ZUrlReader(String name) throws IOException {
// Grab all actual issues urls into new queue.
this.issuesUrlsToVisit = new LinkedList<String>();
readContent();
....
}
...
...
public void readContent() throws IOException {
....
....
// Add it LinkedList
issuesUrlsToVisit.add("http://www.sourceforge.com" + url);
...
}
// return set of collected actual issues' urls
public LinkedList<String> getIssuesUrls() {
return this.issuesUrlsToVisit;
}
在第二个类文件“Crawler.java”上我创建了A2ZUrlRead.java的对象,如下所示:
private void read(String urlpath) {
System.out.println("Reading ... " + urlpath);
try {
// Grab the URLs content for issues
A2ZUrlReader url = new A2ZUrlReader(urlpath);
this.issuesURLsToVistit = url.getIssuesUrls();
...
} catch (Exception e) {
// System.out.println("Problem reading from " + urlpath + " " + e);
// e.printStackTrace();
}
}
public LinkedList<String> getIssuesURLs(){
return this.issuesURLsToVistit;
}
public void print(){
System.out.println("here !!");
while(!this.issuesURLsToVistit.isEmpty()){
String temp = this.issuesURLsToVistit.removeFirst();
System.out.println(temp);
}
}
从主函数我试图使用print()方法打印LinkedList值,但它显示空结果?!!我试图从原始类打印LinkedList值成功!!
任何人都可以帮忙......
答案 0 :(得分:0)
您正在构建对象,但在调用getIssuesUrls()
之前从不调用填充链接列表的方法。
这样的事可能吗?
A2ZUrlReader url = new A2ZUrlReader(urlpath);
url.readContent();
this.issuesURLsToVistit = url.getIssuesUrls();