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 8230741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:14:05+00:00 2026-06-07T17:14:05+00:00

I am probably missing something here, but I’ll try and explain what I want

  • 0

I am probably missing something here, but I’ll try and explain what I want to achieve and then someone please tell me that I am doing it wrong(which I am 🙂 ) and point me in the right direction?

I am using JavaFX 2.0, but I think this problem would lend itself to Swing, or any UI framework.

I want to develope a simple splash screen for my application, when the splash screen starts, I want to have a message label that will be used to update a user on whats happening, in regards to configuring up the back end of the application. My application start up has 2 steps, the first step uses Spring to initialise the Application Context, which in turn initialises the DB (JPA 2.0/Hibernate/etc). The second part of my application start up process will query the DB for the initial data which will be used to populate the UI. Both these steps need to be complete before I can close the splash screen, and between each step I want to update the label in the splash screen to let a user know which stage is being done at that time.

I have broken this down into the following simple program which uses JavaFX and a button, when the button is pressed a new thread is created, that starts another class, which just performs some count to an abitary value, and then another another thread is created to simlate the second step of the start up process, But my issue is here that the second thread attempts to run before the first thread has finished, and as a result runs into a NPE.

Below is a breakdown of some simple code that highlights this issue:

public class Test extends Application
{
    private LongTester lt;
    public static void main(String[] args)
    {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage)
    {
        Button btn = new Button();
        final Label lblText = new Label("Starting");

        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>()
        {
            @Override
            public void handle(ActionEvent event)
            {                
                new Thread(new ConstructorRunnable()).start();

                lblText.setText("More Loading?");

                new Thread(new MethodRunnable()).start();

                lblText.setText("Finished");
            }
        });

        HBox root = new HBox();
        root.getChildren().add(btn);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private class ConstructorRunnable implements Runnable
    {
        @Override
        public void run()
        {
            lt = new LongTester();
        }
    }

    private class MethodRunnable implements Runnable
    {
        @Override
        public void run()
        {
            lt.countAgain();
        }
    }

    private class LongTester
    {
        public LongTester()
        {
            for (int idx = 0; idx < 1000000; idx++)
            {
                System.out.println("Constructor: " + idx);
            }
        }

        public Boolean countAgain()
        {
            for (int idx = 0; idx < 1000000; idx++)
            {
                System.out.println("Method: " + idx);
            }
            return Boolean.TRUE;
        } 
    }
}

Can anyone point out my mistake?

  • 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-07T17:14:08+00:00Added an answer on June 7, 2026 at 5:14 pm

    I’d advise using a Task to execute your startup tasks and message progress back to your splash screen (similar to the approach in this sample created for a prior stackoverflow question on splash screens). If you want stuff in your task to run sequentially, just use one thread for the task rather than two.

    Sample code for your task might look something like:

    final Task<Data> initTask = new Task() {
      @Override protected Data call() throws InterruptedException {
        updateMessage("Initializing Application");
        MyApp.initializeAppContext(); 
        updateMessage("Loading Data");
        Data data = DB.loadData(); 
        updateMessage("Data Loaded");
    
        return data;
      }
    
    showSplash(initStage, initTask);
    new Thread(initTask).start();
    showMainStage(initTask.valueProperty());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm probably missing something very simple here, but please bear with me. What I
I'm probably missing something obvious here but here's what I'm trying to do. From
Probably missing something completely obvious here, but here goes. I'm starting out with Spring
I'm probably missing out on something fundamental here but it seems rather tricky and
OK, I'm probably missing something obvious here, but my searches aren't turning up anything
I'm probably missing something pretty basic here, but if the n-body problem yields chaotic
I'm using Visual Studio 2008 Pro. I'm probably missing something very obvious here, but
I'm probably missing something simple, but ListRows.Add is giving me grief. Here's the function:
I am new to F#, so I am probably missing something trivial but here
I know I am probably missing something pretty basic here, but I am trying

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.