I feel stupid asking this and searched similar questions but I don't understand why I'm able to set private String title but unable to get it.
I have a class that makes an HTTP request to get some JSON, parse it and set the instance variables from processResponse(). When I use GWT.log() inside setTitle() and getTitle(), the console shows that setTitle() has the value but getTitle() is undefined.
I'm using GWT if that makes a difference. This class will be used to create objects and these variables will be used throughout the program. What am I doing wrong here?
public class Requester {
//other variables
private String title;
public Requester(UrlBuilder url) {
this.setURL(url);
this.generateRequest();
}
public void setURL(UrlBuilder url) {
this.url = url;
}
private void generateRequest() {
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url.getUrl()));
builder.setHeader("Authorization", authHeader);
try {
builder.sendRequest(null, new RequestCallback() {
// onError() method
public void onResponseReceived(Request request, Response response) {
processResponse(response);
}
});
} catch (RequestException e) {
//exception code
}
}
private void processResponse(Response response) {
//code to get title and assign it to String output
setTitle(output);
}
private void setTitle(String output) {
this.title = output;
}
public String getTitle() {
return this.title;
}
}