I am building my first Java application using GWT which must read in data from a very large XML file. I am having issues when I try sending a request for the information in the file, and I'm not quite sure if it has to do with the size of the file, or my semantics. In my program I have the following:
static final String xmlurl = "filename.xml";
String xmlData;
...
public void onModuleLoad() {
requestData(xmlurl);
if(xmlData.equals("Error")){
// display error message
return;
} else {
// display the xml
}
void requestData(String url){
final int STATUS_CODE = 200;
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try {
builder.setTimeoutMillis(2000);
builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
xmlData = "Error"
}
public void onResponseReceived(Request request, Response response) {
if (STATUS_CODE == response.getStatusCode()){
xmlData = response.getText();
} else {
xmlData = "Error";
}
}
}
} catch (RequestException e) {
xmlData = "Error";
}
}
I rewrote the code, so I might have made some typos, but for the actual application it compiles and runs. The issue is that I get a nullpointer exception when I try to display the XML and xmlData is never assigned to anything. I tried putting a while loop that waited for it to store either "Error" or the XML text, but the variable was never assigned to. I have the XML file saved in the war directory of my project, and it seems to be able to find the file. I've searched online for similar examples, but everything seemed to be a bit more complicated than what I'm trying to do, and I'm not sure if I need a servlet or a configuration change for this, or if the file is just too big to read into a String. Any help is appreciated. Thanks.