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

The Archive Base Latest Questions

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

Please have a look at the following code of JavaFX and CSS. Login2.java package

  • 0

Please have a look at the following code of JavaFX and CSS.

Login2.java

package helloworld;

import javafx.application.Application;
import javafx.stage.*;
import javafx.scene.*;
import javafx.event.*;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;

public class Login2 extends Application
{
    private Text welcome, message;
    private Label userName, password;
    private Button btn;
    private GridPane grid;
    private TextField userNameField;
    private PasswordField passwordField;
    private Scene scene;
    private HBox hbox, hbox2;



    public static void main(String[]args)
    {
        launch(args);
    }

    @Override
    public void start(Stage stage)
    {
        //Intializing instance Varaibles
        welcome = new Text("Welcome");
        message = new Text();

        userName = new Label("User Name: ");
        password = new Label("Password: ");

        btn = new Button("Submit");
        btn.setOnAction(new Action());

        userNameField = new TextField();
        passwordField = new PasswordField();

        grid = new GridPane();
        grid.setAlignment(Pos.CENTER);
        grid.setVgap(10);
        grid.setHgap(10);


        //Creating the GUI

        hbox = new HBox();
        hbox.getChildren().add(btn);
        hbox.setAlignment(Pos.BOTTOM_RIGHT);

        hbox2 = new HBox();
        hbox2.getChildren().add(message);
        hbox2.setAlignment(Pos.BOTTOM_RIGHT);

        grid.add(welcome,0,0);
        grid.add(userName,0,1);
        grid.add(userNameField,1,1);
        grid.add(password,0,2);
        grid.add(passwordField,1,2);
        grid.add(hbox,1,3);
        grid.add(hbox2,1,4);



        scene = new Scene(grid,300,275);


        stage.setTitle("Welcome Form");
        stage.setScene(scene);

        scene.getStylesheets().add(Login2.class.getResource("Login.css").toExternalForm());
        stage.show();
    }

    private class Action implements EventHandler<ActionEvent>
    {
        public void handle(ActionEvent ae)
        {
            message.setFill(Color.CRIMSON);
            message.setText("You pressed the button");
        }
    }
}

Login.css

/* 
    Document   : Login
    Created on : Jul 14, 2012, 8:04:31 PM
    Author     : Yohan
    Description:
        Purpose of the stylesheet follows.
*/

.root {

   -fx-background-image: url(Desert.jpg);
}

When I run this, I am getting the following error.

Exception in Application start method Exception in thread “main”
java.lang.RuntimeException: Exception in Application start method at
com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown
Source) at com.sun.javafx.application.LauncherImpl.access$000(Unknown
Source) at com.sun.javafx.application.LauncherImpl$1.run(Unknown
Source) at java.lang.Thread.run(Thread.java:722) Caused by:
java.lang.NullPointerException at
helloworld.Login2.start(Login2.java:80) at
com.sun.javafx.application.LauncherImpl$5.run(Unknown Source) at
com.sun.javafx.application.PlatformImpl$4.run(Unknown Source) at
com.sun.javafx.application.PlatformImpl$3.run(Unknown Source) at
com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at
com.sun.glass.ui.win.WinApplication.access$100(Unknown Source) at
com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source) … 1
more Java Result: 1

The uploaded image shows my folder structure.

Why I am getting this error? I can’t understand! This is my third JavaFX code anyway. Please help!

enter image description here

  • 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:58:28+00:00Added an answer on June 7, 2026 at 5:58 pm

    In Netbeans, with default project settings, most of time when the non java resource files are added to the package structure, the project needs to be rebuilded from the scratch. This way new resources will be copied to the “build” folder where the compiled java files are stored and run (without NullPointerException). The rebuild can be done by right clicking the project and doing “Clean and Build”.

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

Sidebar

Related Questions

Please have a look at the following code package Euler; import java.util.ArrayList; import java.util.List;
Please have a look at the following code package normal; import java.io.*; import java.util.*;
Please have a look at following code : import java.util.ArrayList; import java.util.List; class Main{
Please have a look at the following code import java.awt.event.*; import javax.swing.*; import java.awt.*;
Please have a look at the following code. import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.*;
Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*;
Please have a look at the following code import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout;
Please have a look at the following code import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue;
please have a look at the following code import java.util.ArrayList; import java.util.List; public class
Please have a look the following code import javax.swing.*; import java.awt.event.*; import java.awt.*; public

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.