Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6338597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:28:40+00:00 2026-05-24T19:28:40+00:00

I am building my first Java application using GWT which must read in data

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:28:40+00:00Added an answer on May 24, 2026 at 7:28 pm

    Parsing xml at client-side (in browser) is quite slow, and should be avoided; delegating this to server-side is usually faster and therefore more user friendly (big files will cause your browser stop responding for a long time).

    However the decision is yours 😉 Here is what I use for reading files:

    Define this helper method:

    public static void httpGetFile(final String url, final AsyncCallback<String> callback) {
        final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
        rb.setCallback(new RequestCallback() {
            public void onResponseReceived(Request request, Response response) {
                try {
                    final int responseCode = response.getStatusCode() / 100;
                    if (url.startsWith("file:/") || (responseCode == 2)) {
                        callback.onSuccess(response.getText());
                    } else {
                        callback.onFailure(new IllegalStateException("HttpError#" + response.getStatusCode() + " - " + response.getStatusText()));
                    }
                } catch (Throwable e) {
                    callback.onFailure(e);
                }
            }
    
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
        try {
            rb.send();
        } catch (RequestException e) {
            callback.onFailure(e);
        }
    }
    

    In your code, it might look like this:

    ...
        httpGetFile(url, new AsyncCallback<String>() {
            public void onFailure(Throwable caught) {
                xmlData = "Error";
            }
    
            public void onSuccess(String xmlText) {
                xmlData = xmlText;
            }
        }
    ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My team is building our first significant Silverlight application, using a 3 layered architecture
Fellow StackOverflowers, we are building an iOS application that will record data which will
In my web application (my first with Java, Spring, OR Roo), I'm building a
I'm building my first game in Java, from scratch. I've decided that the GameWorld
I am building and sort of RSS reader in java as my first object-oriented
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
I'm building my first ASP.NET MVC application and I am having some troubles with
So I'm building my first ever website with user accounts. What data should I
I'm building my first Facebook Connect application, and am running into an odd problem.
Building decent RIA data-intensive crud-like application is still hard. In spite of existence tons

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.