Im doing a program in GWT. Here is the snippet where Im having problem
private String[] populateRSSData() {
1==>> String[] data = null;
try {
new RequestBuilder(RequestBuilder.GET,
"../database.php?action=populaterss").sendRequest(null,
new RequestCallback() {
@Override
public void onResponseReceived(Request request,
Response response) {
2==>> data=response.getText().split("~");
}
@Override
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage());
}
});
} catch (RequestException e) {
Window.alert(e.getMessage());
}
return data;
}
Now the problem arises that I get an error that the variable 1==>> data should be declared final. But if I declare it as final then i cannot store the datas in 2==>>
The error i get
Cannot refer to a non-final variable data inside an inner class defined in a different method RSS_Manager.java
Please suggest
Even if you manage to get over the error, the function will not do what you intend it to do.
The callback you are creating will be notified asynchronously of the response received from server while your method populateRSSData() will return immediately.
You need to rethink your design taking the asynchrony into account.
EDIT: see Getting Used to Asynchronous Calls
EDIT:
Quote from the above link