2010-12-08 77 views
0

我嘗試使用從API稱J-加萊得到結果,然後出來把結果在網頁上,我寫在客戶端的所有代碼,但它不能編譯權,不知道爲什麼?請幫忙。源代碼象下面這樣:GWT客戶端「拋出異常」的原因compling問題

有出現沒有明顯的錯誤,但它不能是成功編譯.....非常感謝:

公共無效onModuleLoad(){// 創建庫存數據表。 stocksFlexTable.setText(0,0,「Type」); stocksFlexTable.setText(0,1,「Name」);

// Assemble Add Stock panel. 
addPanel.add(newSymbolTextBox); 
addPanel.add(addStockButton); 

// Assemble Main panel. 
mainPanel.add(stocksFlexTable); 
mainPanel.add(addPanel); 
mainPanel.add(lastUpdatedLabel); 

// Associate the Main panel with the HTML host page. 
RootPanel.get("stockList").add(mainPanel); 

// Move cursor focus to the input box. 
newSymbolTextBox.setFocus(true); 

//在添加按鈕上監聽鼠標事件。 addStockButton.addClickHandler(新clickHandler事件(){ 公共無效的onClick(ClickEvent事件){

     try { 
          addStock(); 
         } catch (Exception e) { 
          e.printStackTrace(); 
         } 

    } 
}); 
// Listen for keyboard events in the input box. 
newSymbolTextBox.addKeyPressHandler(new KeyPressHandler() { 
    public void onKeyPress(KeyPressEvent event) { 
    if (event.getCharCode() == KeyCodes.KEY_ENTER) { 
      try { 
       addStock(); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
    } 
    } 
}); 

}

private void addStock() throws Exception { 
    final String url_s = newSymbolTextBox.getText().toUpperCase().trim(); 
    newSymbolTextBox.setFocus(true); 
    newSymbolTextBox.setText(""); 
    int row = stocksFlexTable.getRowCount(); 


    CalaisClient client = new CalaisRestClient("ysw5rx69jkvdnzqf6sgjduqj"); 
    System.out.print("read success...\n"); 
    URL url = new URL(url_s);  
    CalaisResponse response = client.analyze(url);   
     for (CalaisObject entity : response.getEntities()) { 
      System.out.println(entity.getField("_type") + ":" 
           + entity.getField("name")); 
      stocks.add(entity.getField("_type")); 
      stocksFlexTable.setText(row, 0, entity.getField("_type")); 
      stocksFlexTable.setText(row, 1, entity.getField("name")); 
      } 

     for (CalaisObject topic : response.getTopics()) { 
      System.out.println(topic.getField("categoryName")); 
      } 

}

}

+2

請加上你,這將有助於回答你的問題的錯誤。 – 2010-12-08 14:32:33

回答

0

GWT只處理unchecked異常所以你可以扔運行時間Exceptio NS

或寫自己的異常是從運行時異常擴展那麼就不會造成任何編譯時間問題

void f() throws NullPointerException // will not cause any problem because it is Runtime exception so unchecked 

void f() throws IllegalAccessException // it is checked exception so there will be problem at compile time 
+0

它迫使我拋出IOException ... – Camellia 2010-12-15 21:05:09

相關問題