My javafx Code Obfuscated Successfully But now It is not running due to error in loading .fxml File from main method

General Tech Bugs & Fixes 2 years ago

1 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 30 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

I obfuscated my javafx code that contains .fxml files for view. After successful obfuscation when i run the jar file using command line, it shows the error in main method that the code is unable to load .fxml file.

Please help

profilepic.png
manpreet 2 years ago

This may not be what your looking for, but you could always use a FXML to java converter to create an abstract class.
Then you have the controller for the xml file extend the abstract class, you'll have to remove the initialize method (it's no longer necessary) and change the @FXML annotation for any methods that handle events to @Overrides.
Also you'll no longer need any of the fields with an @FXML annotation as all controls will be accessible through the abstract base class. If you use Netbeans there is a plugin to do this available through the plugin portal, or a stand alone jar file can be found here:https://www.tutorialon.com/p/fxmltojavaconverter.html

Then instead of loading fxml you just use the class constructor. For example if the root element in your FXML is a BorderPane, then you would use something like

BorderPane borderPane = new MyClass();

1 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.