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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:59:40+00:00 2026-06-11T12:59:40+00:00

Here is my code: public class TabApp implements Initializable { @FXML Button newButton; @FXML

  • 0

Here is my code:

public class TabApp implements Initializable {

    @FXML
    Button newButton;
    @FXML
    TabPane tabPane = new TabPane();
    public Tab newTab;
    private SingleSelectionModel<Tab> selectionModel;
    public int zQueryTabCount = 2;

    @FXML
    public void handleNewButton(ActionEvent event) {
        System.out.println("new button is pressed");

        newTab = new Tab();

        selectionModel.select(newTab);

        newTab.setId("Query " + zQueryTabCount);

        newTab.setText("Query " + zQueryTabCount);

        tabPane.getTabs().add(tabPane.getTabs().size(), newTab);

        tabPane.getTabs().get(0).setClosable(false);

        newTab.setClosable(true);

        if (zQueryTabCount < 2) {

            tabPane.getTabs().get(0).setClosable(false);

        }

        zQueryTabCount++;

    }
}

I am getting the NullPointerException at the line selectionModel.select(newTab);

How can I resolve it?

  • 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-11T12:59:42+00:00Added an answer on June 11, 2026 at 12:59 pm

    Your selectionModel variable is not initialized nor attached to TabPane.

    Use next call instead:

    [...]
    tabPane.getTabs().add(tabPane.getTabs().size(), newTab);
    
    // should be called after tab has been added to TabPane
    tabPane.getSelectionModel().select(newTab);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my code: public class MyActivity extends Activity implements View.OnClickListener { private Button mHorizontalButton;
So here's my code : public class SetWritable<T extends Writable> implements Writable { private
Here is my code: public class XMLGettersSetters { private ArrayList<String> country = new ArrayList<String>();
Here's the code: public class MyEntryPoint implements EntryPoint { PopupPanel popupPanel = new PopupPanel(false,true);
I've been working on this assignemnt here's code: public class Student { private String
Here is the code: public class MyClass implements Inreface1, Inreface2 { public MyClass() {
here is my code: public class MainMenuActivity extends Activity implements OnClickListener { public int
Here's my code: public class Game extends JComponent implements Runnable { World w =
Here's the code: public class Deck { private Card[] cards; public Deck() { cards
Here is my code: public class Main extends Applet implements Runnable, KeyListener, java.awt.event.MouseListener {

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.