【问题标题】:JavaFX built with netbeans on my 64 bit Mac won't run on 32 bit Linux在我的 64 位 Mac 上使用 netbeans 构建的 JavaFX 无法在 32 位 Linux 上运行
【发布时间】:2014-12-19 06:01:24
【问题描述】:

我有点困惑。我有一个我正在开发的 JavaFX 程序(爱好),它在我的 Mac 上构建和运行得很好。 (我有最新的 Oracle Java 7)。当我运行在 Mac(在最新的 NetBeans 中)上构建的 jar 文件时,在我的 32 位 Linux 系统(也使用最新的 Oracle 版本)上,它给了我以下错误:

java.lang.reflect.InvocationTargetException
file:/home/me/aFolder/SomeOne/Saved/Something.jar!/Something/mainWindow.fxml
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2186)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2744)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2723)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2709)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2696)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2685)
   at Something.Something.start(Something.java:33)
   at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
   at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215)
   at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
   at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
   at java.security.AccessController.doPrivileged(Native Method)
   at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
   at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
   at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
   at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:82)
   at java.lang.Thread.run(Unknown Source)

Something.java:33 的行是我调用的地方

AnchorPane mainWindowPane =     
  (AnchorPane)FXMLLoader.load(UdoMail.class.getResource("mainWindow.fxml"));

所以,我很困惑从哪里开始。这是在我的 Mac 上构建的 jar 文件,移动到 32 位 Linux(运行最新的 32 位 Oracle Java),然后运行。

相当奇怪的是,如果我在 32 位 Linux 上构建它,然后在我的 Mac 上运行 Linux 构建的 jar 文件,我会(实际上)在 Mac 上得到相同的错误。

如果我在构建时在同一个平台上运行,那么一切正常。 (也就是说,如果我获取代码并在 Linux 上构建它,它可以在 Linux 上完美运行,但不能在 Mac 上运行。)

由于我似乎无法在 Linux 上为 Mac 构建的 jar 文件运行调试器(反之亦然),所以我有点不知道从哪里开始寻找。我已经确保我正在使用 File.separator 并寻找其他特定于操作系统的东西,但我想找出 FXMLLoader.java 中的这些行是什么(在源代码中),以了解它为什么会出现问题。注释掉大部分代码后,似乎导致 barf 的行是一个简单的 File 实例化:

File myFile = new File(userDirectoryString);

我使用了很多文件和目录,这一行是我的代码中对文件或目录使用的第一次调用。我已经验证了字符串“userDirectoryString”,它是正确的。

有什么想法吗?

【问题讨论】:

    标签: java cross-platform javafx-2


    【解决方案1】:

    我只能帮助你的想法,你在这里:

    public static final String INITIALIZE_METHOD_NAME = "initialize";
    
    // Initialize the controller
                Method initializeMethod =   getControllerMethods().get(INITIALIZE_METHOD_NAME);
    
                if (initializeMethod != null) {
                    try {
                        MethodUtil.invoke(initializeMethod, controller, new Object [] {});
                    } catch (IllegalAccessException exception) {
                        // TODO Throw when Initializable is deprecated/removed
                        // throw new LoadException(exception);
                    } catch (InvocationTargetException exception) {
                        throw new LoadException(exception);
                    }
                }
    

    您可以在 OpenJFX 中找到此代码。

    我们可以看到,这意味着方法 initialize() 在其工作期间抛出了异常..

    【讨论】:

      【解决方案2】:

      您必须在它应该运行的系统上编译代码。 JVM 扫描您的系统并为您构建它的机器写入字节码。您的代码没有任何问题,这就是 JVM 的工作方式。

      【讨论】:

        猜你喜欢
        • 2012-11-26
        • 2010-10-18
        • 2020-03-22
        • 2013-01-20
        • 2013-11-14
        • 2012-03-12
        • 1970-01-01
        • 1970-01-01
        • 2013-02-23
        相关资源
        最近更新 更多