GWTクライアントは「例外をスローする」という問題を引き起こします
-
10-10-2019 - |
質問
j-calaisというAPIの結果を使用してから、結果をWebページに掲載し、クライアントにすべてのコードを書きますが、右コンパイルできません。なぜわかりませんか?助けてください。以下のようなソースコード:
明らかなエラーは発生しませんが、正常にコンパイルすることはできません.....ありがとうございます:
public void 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(new ClickHandler(){public void 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"));
}
}
}
解決
GWTのみハンドル 未確認の例外 だからあなたは投げることができます ランタイムの例外
または、あなた自身の例外を書いてください 拡張 ランタイムの例外から、コンパイル時間の問題を引き起こしません
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
所属していません StackOverflow