Monday, 6 November 2017

How to get past "InaccessibleObjectException" while running a JavaFX application in Java 9?

When you run a JavaFX project, that was perfectly running fine in Java 8, now in Java 9, you are faced with "InaccessibleObjectException" exception  that is thrown by the Java runtime. It complains that the variables and/or methods that you have declared as private (albeit annotated with @FXML) in your "controller" classes are inaccessible as your project's Java module has not made "open" the containing package to the JDK module "javafx.fxml". Here is the full text of the exception thrown by the runtime in my sample JavaFX project:
java.lang.reflect.InaccessibleObjectException: Unable to make field private javafx.scene.control.Label sample.Controller.nameLabel accessible: module LearningJavaModules does not "opens sample" to module javafx.fxml

I have declared the "nameLabel" Label variable as follows in the controller class:
 @FXML
 private Label nameLabel;

And it has been declared in the corresponding fxml file as below:
<Label fx:id="nameLabel" />

In order to remove this exception, one needs to add the following line to the "module-info.java" file of your project's Java Module:
opens sample to javafx.fxml;

Here is the complete "module-info.java" file of my sample JavaFX project:
module LearningJavaModules {
    requires javafx.graphics;
    requires javafx.fxml;
    requires javafx.controls;
    opens sample to javafx.fxml;
    exports sample;
}

Please note that it has been given in the "JavaFX: New & Notworthy" presentation by Oracle dated September 19, 2016 that one needs to add the following line to the "module-info.java" file:
exports private my.pkg to javafx.fxml;

However, this doesn't work. It seems that the implementation has changed since the above-mentioned presentation by Oracle was released. One now needs to use "opens" instead of "exports" to make private fields accessible to JavaFX runtime.

Trust that you find this useful. :-)

Sunday, 1 October 2017

School Fee Manager - a free and open-sourced JavaFX application

Hi,

I am writing this post to introduce 'School Fee Manager' - an application that I have written for a neighborhood Play School.

This application manages fee payment records and student registration details. It issues fee receipts, generates few MIS reports, and prints Driver Sheet for school bus drivers' who ferry students to the school. It allows for filtering data on almost every screen where it displays the data so as to enable easy access to the relevant data. The filter facility can be accessed on most occasions by right-clicking a table-cell and choosing appropriate option from the context menu.

While generating a fee payment receipt, the application auto calculates the fee due, and auto populates the table that displays the fee items being paid. If a student is paying only a subset of the fee items due, then the remaining fee items can be removed from the receipt. It also provides for editing a fee payment receipt after it is generated to change the payment mode if that may be required.

The options to backup, restore and compact databases are available as they should be available in any good application. Few screenshots of the application are given below:





You can see many more screenshots of the application here.

The entire source code of the application as well as its executable file and Windows setup file is available for download. You can download it from here.

Please note that you need to have Java SE Runtime Environment (JRE) installed in your system in order to run this application. You can get the latest edition of JRE for your system from here.

I trust you will find this application useful. Truly speaking, I myself would have find this application extremely useful if I was learning JavaFX application development.

Should you have any query regarding the application, please use the comment section below to communicate with me.

Thanks for reading this post.

Cheers!