Aaron N. Aaron N. - 1 year ago 97
Java Question

Error in running Java FXML program

I'm getting an error on netbeans when trying to run my java fxml application.

Here is the error I am getting:

Caused by: java.lang.NullPointerException at apnc7dsimulator.UIController.handleStart(UIController.java:4‌​2) at apnc7dsimulator.UIController.handleNew(UIController.java:37) at apnc7dsimulator.UIController.initialize(UIController.java:31‌​) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548) ... 17 more

It appears the error is originating from my controller. Here's my code:

public class UIController implements Initializable {

private TextArea screen;

private TextField commandLine;

private Login login;

public void initialize(URL location, ResourceBundle resources) {

public void handleNew(){


public void handleStart(){


The code the controller references is this:

public class Login implements PrintToScreen{

public void print(String text, TextArea screen) {

public String read(TextArea screen) {
Scanner scanner = new Scanner(System.in);
String readString = scanner.nextLine();
while(readString != null){


readString = scanner.nextLine();
readString = null;
return readString;

public void loginSys (TextArea screen)
String user = "...";
String pass = "...";

print("Please Enter Username:",screen);
user = read(screen);

print("Please Enter Password:",screen);
pass = read(screen);

print("Check Credentials... Please Wait.",screen);

I'm sure it's a simple mistake I'm making or some sort of convention I'm not following correctly but this has had me stumped for a while now.
Any help would be great.

Answer Source

Assuming you've posted all of your code, it appears that the login member variable is never initialized. By default it is initialized to null. The result is that when this line of code runs:


Since login is null, the code is throwing a NullPointerException.

Somewhere in your code, before handleStart() is called, possibly in the UIController constructor, you need to initialize login, something like:

login = new Login();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download