2010-12-08 8 views
0

Ich versuche, Ergebnis von einer API namens j-calais zu erhalten, und dann das Ergebnis auf einer Webseite setzen, schreibe ich den gesamten Code in Client, aber es kompilieren nicht richtig , weiß nicht warum? bitte hilfe. der Quellcode wie unten:GWT-Client "wirft Exception" Ursache compling Problem

gibt es keinen offensichtlichen Fehler auftreten, aber es kann nicht erfolgreich ..... vielen Dank kompiliert sein:

public void onModuleLoad() {// erstellen Tabelle für Bestandsdaten . stocksFlexTable.setText (0, 0, "Typ"); 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); 

// Hören Sie Mausereignisse auf der Schaltfläche Hinzufügen. addStockButton.addClickHandler (neu 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")); 
      } 

}

}

+2

Bitte fügen Sie den Fehler, dass bekommen die Beantwortung Ihrer Frage helfen. –

Antwort

0

GWT verarbeitet nur ungeprüft Ausnahmen so können Sie Runtime Exceptio werfen ns

oder Ihre eigene Exception schreiben, dass von Runtime Exception erstreckt, dann wird es keine Kompilierung Problem verursachen

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

es zwingt mich, IOException zu werfen ... – Camellia

Verwandte Themen