寻求FXML / FXMLLoader错误诊断工具 [英] FXML / FXMLLoader error diagnostic tool(s) sought

查看:169
本文介绍了寻求FXML / FXMLLoader错误诊断工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个大纲用例。我有一个在 JavaFX Scene Builder 中开发的看似有效的FXML文件。它现在是一个非常重要的XML块,并且在FXML文件中的某处存在运行时加载错误。使用预览选项,Scene Builder可以正常工作。我有一个'简单 .fxml'文件,用于验证控制器是否按预期工作,即相同的控件和事件,但没有额外的FXML布局。我已经和我正在进行剪切代码和测试循环以识别带有问题的XML。所以我会在某个时候深究这一点。

Hi, here's an outline use-case. I have a seemingly valid FXML file developed in JavaFX Scene Builder. It is by now a non-trivial chunk of XML and there are runtime load errors somewhere in the FXML file. Scene Builder works fine with the Preview option. I have a 'simple.fxml' file I use to verify that the controller is working as intended, that is same controls and events but without the extra FXML layouts. And I have and I am doing the cut-out-code and test loop to identify the XML with the problem. So I will get to the bottom of this at some point.

目前在Scene Builder和Netbeans FXML编辑器中都没有显示错误,我没有收到错误,如JavaFX - 加载FXML文件错误(#1)。我得到的只是runnable中结束任务的异常,它表示加载器抛出异常。

At present there are no errors showing in Scene Builder nor in the Netbeans FXML editor and I don't get an error with the load as in "JavaFX - loading FXML file error"(#1). All I get is an exception on end task in runnable, which says the loader threw an exception.

发生这些错误。问题是 对FXML文件进行故障排除 有哪些工具可供使用或正在开发中?

These errors happen. The question is what tools are available or under development to Troubleshoot FXML files?

一些想法,问题或选项:

Some thoughts, questions or options:


  1. 这是一个错误吗?要记住作为装载机的黑盒子应该发出某种指示,例如第246行的失败或...表示在哪里看的东西。

  2. 什么技巧或技巧或您有什么建议可以更快地找到/解决此类错误吗?


    • 是否有使用Include的地方


  • 我看到FXML使用SAX,是否可以包装或挂钩解析器并为FXMLLoader提供备用解析器?


  • 例如,控制器可以级联,这样我就可以创建一个根控制器,可以捕获更接近原点的问题。

目前FXML中仅在装载时发现的问题只是时间 - 如果编辑没有看到任何东西,消费和不可预测。我希望看到一些诊断工具,如果有人h

At present problems inside the FXML that are only uncovered at the time of loading are just time-consuming and unpredictable if the editors don't see anything. I'd like to see some diagnostic tools if anyone h

这些是一些相关的'<在开发过程中出现的em>调试'和'疑难解答'提示。也许其中一些可能会在某一天进入FXML验证器或Lint工具(?)这些点没有特别的顺序,它们的编号用于交叉引用。

These are some relevant 'debugging' and 'troubleshooting' tips that come along during development. Perhaps some of these may find their way into a FXML Validator or Lint tool one day(?) The points are in no particular order, they are numbered for cross-reference purposes.


  1. FXML 中的任何控制器标识符都必须 存在,并使用@FXML在Java代码中进行注释。如果缺少注释,FXML将无法加载。

  2. 每个使用@FXML注释的Java名称都应该在FXML标记文件中。说一个名为myLabel的标签:如果代码中使用的myLabel会出现NullPointerException。与#1情况不同,该文件将加载。

  3. 不要在JavaFX中使用NetBeansCompile on Save编译选项。它似乎在看似正确的代码上生成虚假的NullPointerException-s。

  4. 如果您重命名/重构主应用程序,请确保更新构建目标(例如maven或ant)。一些IDE重构代码可能会错过该链接。

  5. FXMLLoader()确实给你一个线索。如果你发现了异常,你可以查看getMessage()...

  1. Any controller identifiers in the FXML must be present and annotated in the Java code with @FXML. If an annotation is missing the FXML won't load.
  2. Every Java name annotated with @FXML should be in the FXML mark-up file. Say a label called, "myLabel": if the myLabel used in the code there will be a NullPointerException. The file will load, unlike case #1.
  3. Don't use the NetBeans "Compile on Save" compile option with JavaFX. It seem to generate spurious NullPointerException-s on seemingly correct code.
  4. If you rename/refactor your main app ensure you update the build target (e.g. maven or ant). Some IDE refactor code can miss that link.
  5. FXMLLoader() does give you one clue. If you catch the exception you can look at the "getMessage()" ...

catch( Exception ex ){
       System.out.println("Exception on FXMLLoader.load()");
       System.out.println( ex.getMessage() );   //-- Doesn't show in stack dump
}


  • 检查你的在FXML资源上输入。小错字是识别和检测的恶魔。这适用于未由编译器或lint检查的任何字符串,而不仅仅是FXML。

  • Check your typing on FXML resources. Small typos are the devil to identify and detect. This goes for any string that isn't checked by a compiler or lint, not just FXML.

    // These two line are not the same:
    Parent root;
    root = FXMLLoader.load(getClass().getResource("Samplle.fxml"));
    root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
    


  • exception.getMessage()是:需要位置 ,对于#6中的拼写错误。

  • There exception.getMessage() is: "Location required", for that typo in #6.

    请记住将FXML名称空间包含在-d文件中,例如在最外面的XML元素上需要。

    Remember to include the FXML namespace with "-d" files, e.g. needed on the outermost XML element.

    <TreeView id="treeView" fx:id="tree" xmlns:fx="http://javafx.com/fxml" ... >
    


  • 希望有所帮助。这些都是基于小型测试和试验的猜测。请修复有关实际工作方式误解的嵌入式假设。

    Hope something helps. These are guesses based on small tests and trials. Please fix embedded assumptions of misunderstandings about how things actually work.

    另请参阅

    see also:


    1. JavaFX - 加载FXML文件错误

    2. 用于应用程序的Android诊断工具(用例)

    3. 我想覆盖FXMLLoader。我该怎么办?

    4. FXMLLoader如何加载FXML的控制器?

    5. 找不到JavaFX的fxml错误(用例)

    6. 类javafx.fxml.FXMLLoader

    7. JavaFX架构(PDF可用),遗憾的是这里没有关于FXML的内容。

    8. FXML简介

    9. FXMLLoader.java源代码

    1. JavaFX - loading FXML file error
    2. Android diagnostic tool for applications (use case)
    3. I would like to override FXMLLoader. How can I do that?
    4. How does FXMLLoader load the FXML's controller?
    5. Cannot locate the fxml error for JavaFX (use case)
    6. Class javafx.fxml.FXMLLoader
    7. JavaFX Architecture (PDF available), unfortunately there's nothing in here about FXML.
    8. Introduction to FXML
    9. FXMLLoader.java source code


    推荐答案

    使用SceneBuilder 2.0和JavaFX2时遇到了同样的问题。问题是SceneBuilder生成JavaFX8代码。代码有效但不兼容100%JavaFX2。也许这可能是你的问题。你应该从FXMLLoader得到一个错误,错误在哪一行。

    I had the same problem using SceneBuilder 2.0 and JavaFX2. The problem is that SceneBuilder generates JavaFX8 code. The code is valid but not 100% JavaFX2 compatible. Maybe that could be your problem. You should get an Exception from the FXMLLoader in which line the error is.

    这篇关于寻求FXML / FXMLLoader错误诊断工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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