我的应用程序的一些部分。一部分使用jsoup从html站点获取作业名称,第二部分显示结果的ArrayList。现在我试图让我的ArrayList显示来自jsoup的结果,但在模拟器上我只有崩溃。这是我的代码:
public class MainActivity extends ActionBarActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
......... (Shortened version)
}
private ArrayList getListData() {
ArrayList<JobItem> results = new ArrayList<JobItem>();
for (int i =0; i<7; i++) {
JobItem jobData = new JobItem();
NewThread nT = new NewThread();
jobData.setHeadline("Job: "+ nT.jobList.get(i)+"\n");
results.add(jobData);
}
return results;
}
}
和
public class NewThread extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... arg) {
Document doc;
try {
doc = (Document) Jsoup.connect("http://www.infosomething.com")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0").get();
job = doc.select("h2.p-job-title a[href]");
for (Element jobs : job) {
jobList.add(jobs.text()+"\n");
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
和
public class JobItem {
private String jobname;
private String jobcompany;
public String getHeadline() {
return jobname;
}
public void setHeadline(String headline) {
this.jobname = jobname;
}
}
另外这两个功能运作良好,但我无法将它们结合起来。我认为问题出在jobData.setHeadline("Job: "+ nT.jobList.get(i)+"\n");
如果我尝试jobData.setHeadline("Something something");
,那么它就可以了。如何修改它?主要目标是使用ArrayList显示我存储的html片段的listView。请帮助新手。