我会在底部列出我的代码,但这里是交易。 我有一个处理方法的解析器类。该方法从网页中提取数据。我想要抓取每一行,将字符串拆分成一个数组,然后将这些值添加到一个对象中,然后将该对象添加到ArrayList中。随着循环的迭代,来自每一行的新值将通过该对象添加到ArrayList中。此代码中的培训相关方法是公共ArrayList的过程()将数据传递给对象
我得到以下编译错误:
构造飞行(字符串)是令牌“[”未定义 语法错误,表达预计在此之后令牌
在ArrayList类型的方法Add(字符串)不适用于参数(飞行)
我在做什么错在这里,以及如何,如果解决?
public class HtmlParser {
public String url;
public String airline;
public static String lastFlight;
static ArrayList<String> capture = new ArrayList<String>();
public HtmlParser(Properties config) throws IOException{
url = config.getProperty("url");
airline = config.getProperty("airline");
print("Fetching.........%s" , url);
}
public ArrayList<String> process() throws IOException{
Document doc = Jsoup.connect(url).get();
Elements tableRow = doc.getElementsByTag("tr");
for(Element tr : tableRow){
if(tr.text().contains(airline)){
String delims = "[ ]+";
String singleRowArray[] = tr.text().split(delims);
Flight f = new Flight(singleRowArray[]);
capture.add(f);
}
}
return capture;
}
这是我的飞行班。
public class Flight {
public Flight(String singleRowArray[]) {
String origin = singleRowArray[0];
String airline1 = singleRowArray[1];
String airline2 = singleRowArray[2];
String flightNo = singleRowArray[3];
String date = singleRowArray[4];
String ArrTime = singleRowArray[5];
String status = singleRowArray[6];
}
}
这里最重要的答案在哪里去了? –