因此,我筛选了一些代码,并且无法排除此空指针异常错误。空指针异常与Jsoup解析
我试图解析从源代码行一表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代码是正确的,但我本来可以有选择困惑,节点元素以及查询。如果任何人都可以帮助它将不胜感激。
关于第72行,如果这是我的代码,我会打破长链方法,并将每个方法调用放在它自己的行上,看看哪个方法调用导致NPE更好。还要考虑使用调试语句。 –
我分手了,它仍然说72行。我曾尝试使用toString在每个间隔打印出来,他们都失败了。 – user1093111
这会让我相信它与getElementById有关,但它没有意义 – user1093111