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

  • SEARCH
  • Home
  • 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 9090831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:28:02+00:00 2026-06-16T22:28:02+00:00

Please help me, as I will go mad with this soon: When I run

  • 0

Please help me, as I will go mad with this soon:

When I run the code, on first occasion loadNewPoint() is executed and displays some data from global variable – allPointsAndPlaces

However when I click a button (from a child class), the same method loadNewPoint() gives me null pointer for allPointsAndPlaces.

I have changed the code structure a lot from an original trying to solve this issue, and moved this method (loadNewPoint()) to a parent class to see, if it would solve the issue.

Parent class:

public class CabbieApp implements EntryPoint {

  private GetLocationsServiceAsync getAllLocationsService = GWT.create(GetLocationsService.class);
  CabbiePoint[] allPointsAndPlaces;
  PointsQuiz quiz;

  /**
   * Entry point method.
   */
  public void onModuleLoad() {

      //Get all the required data from DB
      getAllPointsAndLocations();

  }

  private void loadAppPages(){
      // Associate the Main panel with the HTML host page.
      RootPanel rootPanel = RootPanel.get("pointsList");    

      quiz = new PointsQuiz();

      rootPanel.setStyleName("GWTapp");
      rootPanel.add(quiz.getMainPanel());

      loadNewPoint();

  }


    private void getAllPointsAndLocations() {
        // Initialize the service proxy.
        if (getAllLocationsService == null) {
            getAllLocationsService = GWT.create(GetLocationsService.class);
        }

        // Set up the callback object.
        AsyncCallback<CabbiePoint[]> callback = new AsyncCallback<CabbiePoint[]>() {
          public void onFailure(Throwable caught) {
              System.out.println(caught.getMessage());
          }

          public void onSuccess(CabbiePoint[] result) {
            //allPointsAndPlaces = result;
            System.out.println(result.length);
            allPointsAndPlaces = result;
            loadAppPages();


          }
        };

        // Make the call to the service.
        getAllLocationsService.getLocations(callback);

    }


    void loadNewPoint(){
        int r = Random.nextInt(allPointsAndPlaces.length);
        quiz.CurrentPlace = allPointsAndPlaces[r].getPlaceName();
        quiz.CurrentLocation = allPointsAndPlaces[r].getPlaceLocation();

        quiz.point.setText(quiz.CurrentPlace);
        quiz.location.setText(quiz.CurrentLocation);
        quiz.location.setStyleName("invisibleText");
    }

  }

Child class:

public class PointsQuiz extends CabbieApp{

       VerticalPanel mainPanel = new VerticalPanel();
       HorizontalPanel navigation = new HorizontalPanel();
       TextBox point = new TextBox();
       TextBox location = new TextBox();
       Button showLocation = new Button("Show Location");
       Button nextPoint = new Button("Next Point");
       String CurrentPlace, CurrentLocation;


      public PointsQuiz() {

          // Assemble Add Stock panel.
              navigation.add(showLocation);
              navigation.add(nextPoint);
              navigation.setCellHorizontalAlignment(nextPoint, HasHorizontalAlignment.ALIGN_RIGHT);
              navigation.addStyleName("addPanel");
              mainPanel.setSpacing(5);
              mainPanel.setStyleName("body");
              mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
              mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

            // Assemble Main panel.
            mainPanel.add(point);
            point.setWidth("200px");
            mainPanel.add(location);
            location.setWidth("200px");
            mainPanel.add(navigation);
            navigation.setWidth("200px");

         // Move cursor focus to the input box.
            showLocation.setFocus(true);

         // Listen for mouse events on the show location button.
            showLocation.addClickHandler(new ClickHandler() {
              public void onClick(ClickEvent event) {
                showCurrentLocation();}
              });


             // Listen for mouse events on the next point button.
            nextPoint.addClickHandler(new ClickHandler() {
              public void onClick(ClickEvent event) {
                loadNewPoint();
                  }
            });       
      }



        private void showCurrentLocation(){
            location.setStyleName("visibleText");
        }

        public VerticalPanel getMainPanel() {
            return mainPanel;
        }


}
  • 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-06-16T22:28:03+00:00Added an answer on June 16, 2026 at 10:28 pm

    You are getting null pointer error because of allPointsAndPlaces is null. As per your coding The value of allPointsAndPlaces is assigned after completion of RPC call in getAllPointsAndLocations() method. so the allPointsAndPlaces has some assigned values.

    Here you try to directly access loadNewPoint() method in child class. At a time, allPointsAndPlaces is not assigned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me figure a single query that will transform the data below... |id
I'm relatively new to coding so please help me out here. The code will
Please help. I need a CakePHP 1.2 code that needs to export data from
I need some help with this. Basically I have the following code which I
can someone please help me with this code, i'm missing something but can't figure
Desperate, please help. Will work for food :) I want to be able to
ereg and eregi functions will be deleted from Php. Please help to find alternatives
Please help me somebody to convert unicodestring into string This is how i am
Please help me with this update query. I COMPLETELY understand how redundant this is
please help me arrange these 3 buttons horizontally like this photoshopped image: Please take

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.