0

我尝试使用从名为 j-calais 的 api 获取结果,然后将结果输出到网页上,我在客户端中编写了所有代码,但它无法正确编译,不知道为什么?请帮忙。源代码如下:

没有出现明显的错误,但无法编译成功.....非常感谢:

public void onModuleLoad() { // 为股票数据创建表。stockFlexTable.setText(0, 0, "类型"); stockFlexTable.setText(0, 1, "名称");

// 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);

// 监听 Add 按钮上的鼠标事件。addStockButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) {

                        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"));
          }

}

}

4

1 回答 1

0

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
于 2010-12-08T19:21:21.623 回答