我正在使用Eclipse + GWT来调用iTunes API。这是我想获取信息的URI:
itunes.apple.com/es/rss/topsongs/limit=25/json
控制台没有给我任何错误,也没有给我任何错误。 这是我认为使ChartSearch为null的代码的一部分: (每个Pastebin链接都是Java类)
public class ITunesAPI implements EntryPoint {
private Button searchButton = new Button("Search");
private TextBox searchField = new TextBox();
private HorizontalPanel searchPanel = new HorizontalPanel();
private Label statusLabel = new Label();
private final iTunesServiceAsync iTunesService = GWT.create(iTunesService.class);
public void onModuleLoad() {
searchField.setText("País");
searchPanel.add(searchField);
searchPanel.add(searchButton);
searchPanel.add(statusLabel);
// Add panel to the page
RootPanel.get("form").add(searchPanel);
// Focus the cursor on the name field when the app loads
searchField.setFocus(true);
searchField.selectAll();
searchButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
statusLabel.setText("Searching...");
final String pais = searchField.getText();
RootPanel.get("iTunes").clear();
try{
iTunesService.getChart(pais, new AsyncCallback<ChartSearch>(){
public void onSuccess(ChartSearch result) {
statusLabel.setText("Exito");
showChart(pais, result);
}
public void onFailure(Throwable caught) {
statusLabel.setText("Error");
}
});
}catch(Exception e){
statusLabel.setText("Error (try/catch): " + e.getMessage());
}
}
});
}
private void showChart(String pais, ChartSearch result) {
String output="<fieldset>";
output += "<legend>" + pais + " Top 25 Chart</legend>";
if (result != null) {
for (Entry a : result.getFeed().getEntry()) {
output +="<span>" + a.getTitle().getLabel() + "</span><br/>";
}
}else
output="<span>No results</span>";
output +="</fieldset>";
HTML albums = new HTML(output);
RootPanel.get("iTunes").add(albums);
}
public class iTunesServiceImpl extends RemoteServiceServlet implements iTunesService{
String country;
public ChartSearch getChart(String country) {
this.country = country;
ClientResource cr = new ClientResource("https://itunes.apple.com/" + country + "/rss/topsongs/limit=25/json");
ChartSearch message = cr.get(ChartSearch.class);
return message;
}
如果您需要项目的其余部分或某个特定课程,请告诉我,我很乐意上传它。
谢谢,