gpt4 book ai didi

JavaFX - Mac 断言失败

转载 作者:行者123 更新时间:2023-11-30 04:01:38 24 4
gpt4 key购买 nike

当我尝试从其他类调用 JavaFX 应用程序时,我在 Mac 上遇到以下错误。

2014-02-18 15:30:10.285 java[54215:507] *** Assertion failure in -[NSMenu itemAtIndex:], /SourceCache/AppKit/AppKit-1265/Menus.subproj/NSMenu.m:865
2014-02-18 15:30:10.287 java[54215:507] Invalid parameter not satisfying: (index >= 0) && (index < [_itemArray count])
2014-02-18 15:30:10.289 java[54215:507] (
0 CoreFoundation 0x00007fff892d541c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff86065e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff892d51f8 +[NSException raise:format:arguments:] + 104
3 Foundation 0x00007fff8abd4c61 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4 AppKit 0x00007fff89425ea6 -[NSMenu itemAtIndex:] + 164
5 AppKit 0x00007fff89420f9f -[NSApplication(NSWindowsMenu) setWindowsMenu:] + 229
6 libglass.dylib 0x0000000117e03057 -[GlassApplication runLoop:] + 1559
7 Foundation 0x00007fff8ab400de __NSThreadPerformPerform + 229
8 CoreFoundation 0x00007fff892068f1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
9 CoreFoundation 0x00007fff891f8062 __CFRunLoopDoSources0 + 242
10 CoreFoundation 0x00007fff891f77ef __CFRunLoopRun + 831
11 CoreFoundation 0x00007fff891f7275 CFRunLoopRunSpecific + 309
12 HIToolbox 0x00007fff87226f0d RunCurrentEventLoopInMode + 226
13 HIToolbox 0x00007fff87226cb7 ReceiveNextEventCommon + 479
14 HIToolbox 0x00007fff87226abc _BlockUntilNextEventMatchingListInModeWithFilter + 65
15 AppKit 0x00007fff8942e28e _DPSNextEvent + 1434
16 AppKit 0x00007fff8942d8db -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
17 libosxapp.dylib 0x0000000111f056f4 -[NSApplicationAWT nextEventMatchingMask:untilDate:inMode:dequeue:] + 124
18 AppKit 0x00007fff894219cc -[NSApplication run] + 553
19 libosxapp.dylib 0x0000000111f05557 +[NSApplicationAWT runAWTLoopWithApp:] + 156
20 liblwawt.dylib 0x0000000111e5dba9 -[AWTStarter starter:] + 873
21 Foundation 0x00007fff8ab400de __NSThreadPerformPerform + 229
22 CoreFoundation 0x00007fff892068f1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
23 CoreFoundation 0x00007fff891f8062 __CFRunLoopDoSources0 + 242
24 CoreFoundation 0x00007fff891f77ef __CFRunLoopRun + 831
25 CoreFoundation 0x00007fff891f7275 CFRunLoopRunSpecific + 309
26 java 0x00000001064d23b0 CreateExecutionEnvironment + 871
27 java 0x00000001064ccb5c JLI_Launch + 1952
28 java 0x00000001064d270d main + 101
29 java 0x00000001064cc3b4 start + 52
)

我不知道我做错了什么。这是我的 JavaFX 应用程序类

package org.parabot.core.ui;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Circle;
import javafx.scene.shape.CircleBuilder;
import javafx.stage.Stage;

/**
* User: Jeroen
* Date: 18/02/14
* Time: 15:12
*/
public class NetworkUI extends Application {
@Override
public void start(final Stage primaryStage) {
Platform.runLater(new Runnable() {
public void run() {
try {
primaryStage.setTitle("JavaFX Abacus");
Pane root = new Pane();

Circle circle = CircleBuilder.create()
.radius(20)
.centerX(20)
.centerY(20)
.build();
root.getChildren().

add(circle);

primaryStage.setScene(new

Scene(root, 400, 400)

);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}

}
});
}


public static void main() {
launch();
}
}

我使用以下代码调用该类

NetworkUI.main();

我正在使用 Java 版本“1.7.0_51”并通过 IntelliJ 运行此代码。我已将库“jfxrt.jar”添加到 IntelliJ 中的库文件中。

我做错了什么?任何帮助将不胜感激!

顺便说一句,我找不到有关此问题的任何其他帖子,请随时证明我错了:)

真诚的,杰罗恩

最佳答案

如果您尝试从 Swing 中运行 JavaFX,您可能需要跳过一些步骤。如果它适合您,您可能需要创建一个 JFXPanel,然后运行您的 JavaFX 代码:

import javafx.embed.swing.JFXPanel;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class SomeClass {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame("Swing Frame");
JFXPanel jfxp = new JFXPanel();
frame.getContentPane().add(jfxp);
frame.setSize(600, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

NetworkUI.main();
}
});
}
}

将您的 JavaFX Scene 放入 JFXPanel (JFXPanel.setScene) 中可能是有意义的。

这能解决您的问题吗?

关于JavaFX - Mac 断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21856908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com