You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac运行Windows开发的JavaFX项目报NSInternalInconsistencyException错误

问题

我们团队在大学项目中首次开发JavaFX程序,对Java不算熟悉。我用MacOS,其他成员用Windows 11,开发工具都是IntelliJ。有个成员创建项目完成GUI初始开发后推到GitHub,其他成员拉取后都能正常运行(不确定他们是否需要先在IDE里导入JavaFX库)。我已经下载了Mac版JavaFX库并完成导入,但运行代码时出现如下错误:

Apr 13, 2025 11:53:00 PM com.sun.glass.ui.mac.MacApplication lambda$waitForReactivation$6 WARNING: Timeout while waiting for app reactivation
Apr 13, 2025 11:53:00 PM javafx.fxml.FXMLLoader$ValueElement processValue WARNING: Loading FXML document with JavaFX API of version 23.0.1 by JavaFX runtime of version 17.0.6
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '0x0 is an invalid NSTrackingRectTag. Common possible reasons for this are: 1. already removed this trackingRectTag, 2. Truncated the NSTrackingRectTag to 32bit at some point.'
*** First throw call stack:
(
0 CoreFoundation 0x000000018f36ddf0 __exceptionPreprocess + 176
1 libobjc.A.dylib 0x000000018ee32b60 objc_exception_throw + 88
2 Foundation 0x0000000190696a78 -[NSCalendarDate initWithCoder:] + 0
3 AppKit 0x00000001937e5290 -[_NSTrackingAreaAKViewHelper removeTrackingRect:] + 200
4 libglass.dylib 0x000000012070ef7c Java_com_sun_glass_ui_mac_MacApplication__1getMacKey + 3456
5 libglass.dylib 0x0000000120714074 RemoteLayerHostRemoteIdInLocal + 3620
6 AppKit 0x0000000192f8617c -[NSView setFrame:] + 300
7 libglass.dylib 0x00000001207140d4 RemoteLayerHostRemoteIdInLocal + 3716
8 AppKit 0x0000000192f92b88 -[NSView resizeWithOldSuperviewSize:] + 488
9 AppKit 0x0000000192f92524 -[NSView resizeSubviewsWithOldSize:] + 360
10 AppKit 0x0000000192f789ac -[NSView setFrameSize:] + 948
11 AppKit 0x0000000192f8617c -[NSView setFrame:] + 300
12 AppKit 0x0000000192f92b88 -[NSView resizeWithOldSuperviewSize:] + 488
13 AppKit 0x0000000192f92524 -[NSView resizeSubviewsWithOldSize:] + 360
14 AppKit 0x0000000192f789ac -[NSView setFrameSize:] + 948
15 AppKit 0x0000000192f9167c -[NSThemeFrame setFrameSize:] + 244
16 AppKit 0x0000000192f90fe4 -[NSWindow _oldPlaceWindow:fromServer:] + 532
17 AppKit 0x0000000192f90458 -[NSWindow _setFrameCommon:display:fromServer:] + 1988
18 libglass.dylib 0x000000012071f0c4 Java_com_sun_glass_ui_mac_MacWindow__1setBounds2 + 416
19 ??? 0x0000000111fe8fd4 0x0 + 4596862932
20 ??? 0x0000000111fe5110 0x0 + 4596846864
...
42 ??? 0x0000000111fe56b0 0x0 + 4596848304
43 ??? 0x0000000111fe0114 0x0 + 4596826388
44 libjvm.dylib 0x000000010163dd60 _ZN9JavaCalls11call_helperEP9JavaValueRK12methodHandleP17JavaCallArgumentsP10JavaThread + 600
45 libjvm.dylib 0x000000010169a114 _ZL20jni_invoke_nonstaticP7JNIEnv_P9JavaValueP8_jobject11JNICallTypeP10_jmethodIDP18JNI_ArgumentPusherP10JavaThread + 644
46 libjvm.dylib 0x000000010169da28 jni_CallVoidMethod + 212
47 libglass.dylib 0x000000012070a998 JNI_OnLoad + 204
48 Foundation 0x0000000190601f74 __NSThreadPerformPerform + 264
49 CoreFoundation 0x000000018f2fcde4 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28
50 CoreFoundation 0x000000018f2fcd78 __CFRunLoopDoSource0 + 172
51 CoreFoundation 0x000000018f2fcae4 __CFRunLoopDoSources0 + 232
52 CoreFoundation 0x000000018f2fb738 __CFRunLoopRun + 840
53 CoreFoundation 0x000000018f2fad68 CFRunLoopRunSpecific + 572
54 HIToolbox 0x000000019aaab27c RunCurrentEventLoopInMode + 324
55 HIToolbox 0x000000019aaae4e8 ReceiveNextEventCommon + 676
56 HIToolbox 0x000000019ac39484 _BlockUntilNextEventMatchingListInModeWithFilter + 76
57 AppKit 0x0000000192f4dab4 _DPSNextEvent + 684
58 AppKit 0x00000001938eacd4 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 688
59 AppKit 0x0000000192f40c64 -[NSApplication run] + 480
60 libglass.dylib 0x000000012070cb20 JNI_OnLoad + 8788
61 Foundation 0x0000000190601f74 __NSThreadPerformPerform + 264
62 CoreFoundation 0x000000018f2fcde4 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28
63 CoreFoundation 0x000000018f2fcd78 __CFRunLoopDoSource0 + 172
64 CoreFoundation 0x000000018f2fcae4 __CFRunLoopDoSources0 + 232
65 CoreFoundation 0x000000018f2fb738 __CFRunLoopRun + 840
66 CoreFoundation 0x000000018f2fad68 CFRunLoopRunSpecific + 572
67 libjli.dylib 0x000000010015726c CreateExecutionEnvironment + 400
68 libjli.dylib 0x0000000100153344 JLI_Launch + 1128
69 java 0x0000000100117bac main + 392
70 dyld 0x000000018ee72b4c start + 6000
)
libc++abi: terminating due to uncaught exception of type NSException

其中版本不匹配的警告其他成员也会出现,但程序能正常运行,所以我觉得这个警告和当前报错无关。我猜测是用了Windows专属元素,尝试移除代码里的primaryStage.setMaximized(true)但没用。以下是Main类代码:

package com.example.bingespice_app;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("Homepage.fxml"));
        Scene scene = new Scene(root);

        // Set a default size before maximizing
        primaryStage.setWidth(1280);
        primaryStage.setHeight(720);

        // Optional: center the window before maximizing
        primaryStage.centerOnScreen();

        // Add listener to handle when maximized is changed
        primaryStage.maximizedProperty().addListener((obs, wasMaximized, isNowMaximized) -> {
            if (isNowMaximized) {
                // You can check screen bounds and ensure it doesn't exceed a max
                javafx.geometry.Rectangle2D screenBounds = javafx.stage.Screen.getPrimary().getVisualBounds();
                if (screenBounds.getWidth() < 1280 || screenBounds.getHeight() < 720) {
                    // If the screen is too small, don't maximize; instead, set default size
                    primaryStage.setMaximized(false);
                    primaryStage.setWidth(1280);
                    primaryStage.setHeight(720);
                    primaryStage.centerOnScreen();
                }
            }
        });

        primaryStage.setScene(scene);
        primaryStage.setMaximized(true);
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch();
    }
}
解决方案
  • 统一JavaFX版本:错误里明确提示FXML用的是23.0.1版本,但你的运行时是17.0.6。虽然Windows上能跑,但Mac对版本兼容性更敏感。把你的JavaFX库版本换成和项目一致的23.0.1,确保开发环境和运行时版本匹配。
  • 调整窗口初始化顺序:MacOS下JavaFX窗口的初始化顺序可能和Windows不同,试试把primaryStage.show()放在setMaximized(true)之前,调整后的代码片段如下:
    primaryStage.setScene(scene);
    primaryStage.show();
    primaryStage.setMaximized(true);
    
  • 简化最大化状态监听逻辑:当前监听里在窗口最大化时又设置窗口大小并取消最大化,可能触发MacOS的UI层异常。可以暂时注释掉监听代码测试,或者简化逻辑只做屏幕尺寸判断,避免重复修改窗口状态。
  • 检查FXML中的组件:虽然你没贴FXML代码,但可能里面用了一些在MacOS上有兼容性问题的组件或布局属性,比如某些Windows专属的控件样式、布局约束。可以先替换成基础的JavaFX组件(比如用AnchorPane代替可能有问题的布局)测试。
  • 更新IntelliJ的JavaFX配置:确保IntelliJ中运行配置的VM参数正确指向Mac版JavaFX库,并且没有残留的Windows相关配置。VM参数示例:
    --module-path /path/to/javafx-sdk-23.0.1/lib --add-modules javafx.controls,javafx.fxml
    

内容的提问来源于stack exchange,提问作者AndreasKaram

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 10:55:54