所以我已经筛选了一些代码并且无法解决这个空指针异常错误。
我正在尝试从源代码行2290到3153解析表http://pastebin.com/DjGHED5t
然而,在我的一个CSS查询中,代码失败了,对我来说没有任何意义。
public void updateCompanyIs()throws IOException{
investoolsLogin();
Document doc = Jsoup.connect("http://toolbox.investools.com/graphs/fundamentalAnalysis.iedu?report=BS&symbol="+(Ticker)).get();
// Elements table = doc.select("table");
/**LINE 72**/
Elements columns = doc.getElementById("fundamentalsForm").children().select("table").get(0).select("tr").get(0).select("td");
Iterator<Element> columnIterator = columns.iterator();
int col = 0;
int row = 0;
while (columnIterator.hasNext()) {
Element column = columnIterator.next();
Elements rows = column.select("table").get(0).select("tr");
Iterator<Element> rowsIterator = rows.iterator();
col = col + 1;
while (rowsIterator.hasNext()){
row = row + 1;
//Element rowIterator.next = ;
incomeStatementInfo[col][row] = rowsIterator.next();
}
}
}
public void updateCompanyBs()throws IOException{
investoolsLogin();
Document doc = Jsoup.connect("http://toolbox.investools.com/graphs/fundamentalAnalysis.iedu?report=BS&symbol="+(Ticker)).get();
// Elements table = doc.select("table");
Elements columns = doc.getElementById("fundamentalsForm").children().select("table").get(0).select("tr").get(0).select("td");
Iterator<Element> columnIterator = columns.iterator();
int col = 0;
int row = 0;
while (columnIterator.hasNext()) {
Element column = columnIterator.next();
Elements rows = column.select("table").get(0).select("tr");
Iterator<Element> rowsIterator = rows.iterator();
col = col + 1;
while (rowsIterator.hasNext()){
row = row + 1;
//Element rowIterator.next = ;
balanceSheetInfo[col][row] = rowsIterator.next();
}
}
}
public void updateCompanyCf()throws IOException{
investoolsLogin();
Document doc = Jsoup.connect("http://toolbox.investools.com/graphs/fundamentalAnalysis.iedu?report=BS&symbol="+(Ticker)).get();
// Elements table = doc.select("table");
Elements columns = doc.getElementById("fundamentalsForm").children().select("table").get(0).select("tr").get(0).select("td");
Iterator<Element> columnIterator = columns.iterator();
int col = 0;
int row = 0;
while (columnIterator.hasNext()) {
Element column = columnIterator.next();
Elements rows = column.select("table").get(0).select("tr");
Iterator<Element> rowsIterator = rows.iterator();
col = col + 1;
while (rowsIterator.hasNext()){
row = row + 1;
//Element rowIterator.next = ;
cashFlowsInfo[col][row] = rowsIterator.next();
}
}
}
public void updateCompanyInfo(String Ticker) throws IOException {
/** LINE 134**/
updateCompanyIs();
updateCompanyBs();
updateCompanyCf();
}
}
这是错误:
Exception in thread "main" java.lang.NullPointerException
at Company.updateCompanyIs(Company.java:72)
at Company.updateCompanyInfo(Company.java:134)
at Company.<init>(Company.java:41)
at AppGUI.main(AppGUI.java:124)
这是我的AppGUI:
public static void main(String[] args) throws Exception{
Company company = new Company("KO"); // Creates new Company. Updating methods are called from constructor automatically.
AppGUI frame = new AppGUI(company); // Creates new App GUI. Various panes are initialized from constructor.
frame.retrieveGUI(company);
frame.setTitle("Financial Calculator | Ratios");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setMinimumSize(new Dimension(1000, 500));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
我认为我的JSOUP代码是正确的,但我可能会对select和node元素以及查询感到困惑。如果有人能提供帮助,我们将不胜感激。
答案 0 :(得分:0)
第72行:Elements columns = doc.getElementById("fundamentalsForm").children().select("table").get(0).select("tr").get(0).select("td");
根据评论判断,似乎doc.getElementById("fundamentalsForm")
正在产生NPE。
我怀疑每个有效页面都有“fundamentalsForm”形式,因此不应该是问题。您是否检查并发现您没有触发错误页面(即未注册该滚动条)?