FXML load()期间的JavaFX IllegalAccessException [英] JavaFX IllegalAccessException during FXML load()

查看:267
本文介绍了FXML load()期间的JavaFX IllegalAccessException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由以下代码调用的对话框窗口( DialogController 是一个使用模态对话框窗口的辅助类;它主要将控制器引用与其窗口捆绑在一起):

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(
            CensusAssistant.RES_FXML_DIALOG_SERVEDIT,
            CensusAssistant.RES_STRING_SERVEDIT,
            this.getDialog());
    sre.setDialogMode(DB.DBEDIT_MODE_EDIT,
                      tbvService.getItems(),
                      tbvService.getSelectionModel().getSelectedIndex(),
                      m_encCal);
    sre.showAndWait();

    sre.release();
    this.updateGUI();
}

我已经确认在期间我收到了异常FXMLLoader.load()方法。我还确定错误发生在我的 initialize()方法中的任何代码都有机会运行之前。我从 load()获得的一些堆栈跟踪在这里:

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 org.kls.md.censusassistant.DCServRecEditor 
    with modifiers ""
file:/D:/Documents/NetBeansProjects/CensusAssistant/dist/run1284250063/CensusAssistant.jar!/org/kls/md/censusassistant/fxml/GUIServRecEditor.fxml:13
  at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:738)
  at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:775)
  at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:180)
  at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:563)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
  at org.kls.md.censusassistant.DialogController.loadFXML(DialogController.java:63)
  at org.kls.md.censusassistant.DCMainEditor.handleServicesEdit(DCMainEditor.java:330)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        ...

Caused by: java.lang.IllegalAccessException: Class sun.reflect.misc.ReflectUtil
    can not access a member of class org.kls.md.censusassistant.DCServRecEditor
    with modifiers "" 
  at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:95)
  at java.lang.Class.newInstance0(Class.java:368)
  at java.lang.Class.newInstance(Class.java:327)
  at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:46)
  at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:731)
... 66 more

我的类 DCServRecEditor DialogController 的子类。这是一个非常正常的FXML控制器类:

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

        ...
}

我进行了双重和三重检查,以确保FXML中没有一个命名控件,在控制器类中也没有实例字段。
所有实例字段都标有 @FXML

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.

FXML中控制器类的名称与我的java文件相同,并且是合格的。
错误发生在调用 initialize()之前,所以我不认为它是 initialize(),虽然我已经检查确保它也标有 @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.

我的骨架控制器类是从 Scene Builder 复制并粘贴的......我已经回去并从 Scene Builder 中重新编写了一些东西,以确保没有控件我我的java文件中缺少。

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.

错误消息没有给出关于它有问题的成员的具体信息,除了说它有修饰符。
我回到我的控制器类并使所有成员都默认访问 public ,我仍然收到错误。

我不喜欢甚至不知道我班上的问题来自哪里。
任何人对这里出了什么问题都有任何想法吗?

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?

推荐答案

另一个令人尴尬的简单问题。

Yet another embarrassingly simple problem.

我很惊讶有人现在没有跳过这个。

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

问题出现在我班上 DCServRecEditor 。请注意,该类是使用 default 访问权限声明的。

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

JavaFX要求控制器类别为 public

JavaFX requires that controller classes be made public.

为了公平对待自己,Java在这种情况下的错误报告是令人憎恶和误导的。堆栈跟踪清楚地表明Java抱怨无法访问我的类的成员,因此我专注于我的实例字段和方法。 Java真的应该抱怨它无法访问它本身的类本身而不是它的成员。

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.

这篇关于FXML load()期间的JavaFX IllegalAccessException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆