JavaFX IllegalAccessException during FXML load()


I have a dialog window that is invoked by the following code (DialogController is a helper class for using modal dialog windows; it mainly bundles together a controller reference with its window):

void handleServicesEdit(ActionEvent event) throws IOException {

    DCServRecEditor sre = DialogController.<DCServRecEditor>loadFXML(


I have confirmed that I get an exception during the FXMLLoader.load() method. I have also determined that the error occurs before any code in my initialize() method has a chance to run. Some of the stack trace that I get from load() is here:

java.lang.IllegalAccessException: Class sun.reflect.misc.ReflectUtil 
    can not access a member of class 
    with modifiers ""
  at javafx.fxml.FXMLLoader$ValueElement.processAttribute(
  at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(
  at javafx.fxml.FXMLLoader$Element.processStartElement(
  at javafx.fxml.FXMLLoader$ValueElement.processStartElement(
    at javafx.fxml.FXMLLoader.processStartElement(
  at javafx.fxml.FXMLLoader.load(
  at javafx.fxml.FXMLLoader.load(
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Caused by: java.lang.IllegalAccessException: Class sun.reflect.misc.ReflectUtil
    can not access a member of class
    with modifiers "" 
  at sun.reflect.Reflection.ensureMemberAccess(
  at java.lang.Class.newInstance0(
  at java.lang.Class.newInstance(
  at sun.reflect.misc.ReflectUtil.newInstance(
  at javafx.fxml.FXMLLoader$ValueElement.processAttribute(
... 66 more

My class DCServRecEditor is a subclass of DialogController. It is a pretty normal looking FXML controller class:

class DCServRecEditor extends DialogController {

    private int m_dialogMode = DB.DBEDIT_MODE_ADD;
    private int m_selServ = -1;
    private GregorianCalendar m_cal = null;

    @FXML // ResourceBundle that was given to the FXMLLoader
    private ResourceBundle resources;

    @FXML // URL location of the FXML file that was given to the FXMLLoader
    private URL location;

    @FXML // fx:id="ancMatchSelector"
    private AnchorPane ancMatchSelector; // Value injected by FXMLLoader

    @FXML // fx:id="ancServEditor"
    private AnchorPane ancServEditor; // Value injected by FXMLLoader

    @FXML // fx:id="ancServRecEditor"
    private AnchorPane ancServRecEditor; // Value injected by FXMLLoader


I have double and triple checked to make sure that there wasn't a named control in the FXML that didn't also have an instance field in the controller class. All the instance fields are tagged with @FXML.

The name of the controller class in the FXML is the same as my java file and is properly qualified. The error occurs before initialize() is called, so I don't think it's anything with initialize(), although I have checked to make sure it is also tagged with @FXML.

The skeleton for my controller class was copied and pasted from Scene Builder ... I've gone back and repasted blocks of stuff from Scene Builder to be sure that there wasn't a control I was missing in my java file.

The error message gives me no specifics about the member it is having its problem with, other than to say it has modifiers "". I went back to my controller class and made all the members with default access public, and I still get the error.
I don't even know where in my class the problem is coming from. Anyone have any ideas about what is going wrong here?

7/25/2016 10:13:44 AM

Accepted Answer

Yet another embarrassingly simple problem.

I'm surprised someone didn't jump on this by now.

The problem was in my class DCServRecEditor. Note that the class was declared with default access permission.

JavaFX requires that controller classes be made public.

To be fair to myself, Java's error reporting in this situation is abominable and misleading. The stack trace clearly shows that Java is complaining about being unable to access a member of my class, hence my focus on my instance fields and methods. Java really should have complained that it was the class itself that it could not access and not its members.

7/25/2016 11:03:37 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow