因此,我篩選了一些代碼,並且無法排除此空指針異常錯誤。空指針異常與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