• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with these errors

 
Ertan Hasani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i started learning JavaFX , and watched a tutorial.
When i click the button it shows me these errors , and i have no idea how to fix this.

Main.java



MainItemsController.java



MainItems.fxml


ElectricalDep.fxml


OUTPUT:
 
Knute Snortum
Bartender
Pie
Posts: 2887
62
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that the error is caused because it can't load the FXML file.  Try using this template for loading FXML:
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would that cause this NPE, though?
There's no way that loader can be null.  It's not created by a factory, but by a constructor.

Caused by: java.lang.NullPointerException
    at employee.Main.showElectricalScene(Main.java:64)

That's the root, according to that stack trace.
The line numbers don't match the posted code so I can't tell which line is causing the issue, but it's not going to be loader.
 
Ertan Hasani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I suspect that the error is caused because it can't load the FXML file.  Try using this template for loading FXML:

Dave Tolls wrote:Would that cause this NPE, though?
There's no way that loader can be null.  It's not created by a factory, but by a constructor.

Caused by: java.lang.NullPointerException
    at employee.Main.showElectricalScene(Main.java:64)

That's the root, according to that stack trace.
The line numbers don't match the posted code so I can't tell which line is causing the issue, but it's not going to be loader.



Here it is code with its own lines. (MainView.fxml, MainItems.fxml and ElectricalDep.fxml are same ).

Main.java


MainItemsController.java


OUTPUT:


if i change line 20 in MainItemsController.java
from:

to


the output changes to:


 
Ertan Hasani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW this is the tutorial , i did it all the same , but when i try to make the method "showElectricalScene()" in Main.java STATIC , it doesnt let me because BorderPane its not static , and other lines are all the same as tutorial, but have no idea why.

 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't do video tutorials I'm afraid, but your issue is that certain things are not wired up for whatever reason.
In the first case it's because (as you show) main has not been instantiated.
In the second it's because mainLayout has not been instantiated.

Whether there's an annotation missing, or something around construction of the objects I can't say.
 
Ertan Hasani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:Can't do video tutorials I'm afraid, but your issue is that certain things are not wired up for whatever reason.
In the first case it's because (as you show) main has not been instantiated.
In the second it's because mainLayout has not been instantiated.

Whether there's an annotation missing, or something around construction of the objects I can't say.


I instantiated both of them but still the same.
 
Ertan Hasani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys for help but i fixed it , all i needed to do was , to make mainLayout and the the method showElectricalScene() static in Main.java .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic