Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

!!!! Exception in Application start method

 
Ranch Hand
Posts: 138
4
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I am trying to create a JavaFX application and for testing purpose I decided to run it, I was using a tutorial for guidance and the tutorial app works fine but mine is not and I have no idea why.

Here is my stackTrace:



And here is my code:


 
Saloon Keeper
Posts: 11881
253
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You set the location wrongly. Very carefully read the documentation for Class.getResource().
 
Yosuf Ibrahim
Ranch Hand
Posts: 138
4
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:You set the location wrongly. Very carefully read the documentation for Class.getResource().



I have tried all the following and i still get the same error:


I moved my MainApp Class to the same package as MainScreenController and tried them all again as well and I still get the exact same error
 
Sheriff
Posts: 7051
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've found that finding resources can be very tricky in JavaFX.  Here's how I load my FXML files:
That way you can check if url is null and halt the program.  In general, I stay away from setLocation() and use the FXMLLoader constructor.

What is fxmlPath is is also tricky.  If you have your resource folder and environment setup correctly, it can be as simple as "ResourceName.fxml".  
 
Yosuf Ibrahim
Ranch Hand
Posts: 138
4
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:I've found that finding resources can be very tricky in JavaFX.  Here's how I load my FXML files:
That way you can check if url is null and halt the program.  In general, I stay away from setLocation() and use the FXMLLoader constructor.

What is fxmlPath is is also tricky.  If you have your resource folder and environment setup correctly, it can be as simple as "ResourceName.fxml".  



Ah, now I found the issue thanks to you but it still doesnt solve my problem, I have tried your solution and after declaring the Url url = bla bla I tried printing out the URL and it keeps printing me a null in console, why??
 
Knute Snortum
Sheriff
Posts: 7051
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If url is null, that means the resource could not be found.  That probably means that fxmlPath is not correct.  Read the documentation on getResource() as was already suggested.  Pay particular attention to the "absolute" versus "relative" URLs.

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html#getResource(java.lang.String)
 
Knute Snortum
Sheriff
Posts: 7051
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are still having problems, please post your project's directory structure and which if any build framework you are using (e.g. Maven).
 
Yosuf Ibrahim
Ranch Hand
Posts: 138
4
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:If url is null, that means the resource could not be found.  That probably means that fxmlPath is not correct.  Read the documentation on getResource() as was already suggested.  Pay particular attention to the "absolute" versus "relative" URLs.

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html#getResource(java.lang.String)






It is there
 
Stephan van Hulst
Saloon Keeper
Posts: 11881
253
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your resource is in the same package as or a subpackage of your class, you can use a relative resource path. That means that you should be able to use:

Then pass the URL to the FXMLLoader constructor.
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic