JavaFX - Mac断言失败

时间:2014-02-18 14:33:38

标签: java macos javafx java-7

当我尝试从其他类调用我的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中的库文件中。

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

是的,我找不到关于这个问题的任何其他帖子,随意证明我错了:)

此致 的Jeroen

1 个答案:

答案 0 :(得分:2)

如果您尝试在JavaFX内运行Swing,则可能需要跳过几次箍。如果它适合您,您可能需要创建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放入JFXPanelJFXPanel.setScene)可能有意义。

这能解决您的问题吗?