1

I'm just starting on a large new project, containing the line menuBar = new MenuBar(); MenuBar is packaged in javafx.scene.control. No errors, but when it comes across this line at runtime I get

Exception in thread "AppKit Thread" java.lang.NoClassDefFoundError: Could not initialize class javafx.scene.control.MenuBar

Google suggests there's a discrepancy between my build path and my runtime path. What I'm not sure about is how to actually tell what the build paths and runtime paths are, although I think I have it right.

Build path: I go to

Properties -> Java Build Path 

and see that JRE System Library [Java SE 8 [1.8.0_77]] is there. I furthermore confirm that it contains jfxrt.jar. It also detects no errors at build time so I can assume it's working just due to that.

Runtime path: I go to

Run As -> Run Configurations... -> Classpath 

and see that JRE System Library [Java SE 8 [1.8.0_77]] is listed in Bootstrap Entries. I don't seem to be able to expand that and confirm that it contains the relevant jar.

Am I missing anything in the runtime classpath?

EDIT: I found another symptom, or a nuance to this. The menuBar = new MenuBar() is contained in the constructor of an object that extends the FX Stage class. The constructor is initialized by clicking a button on a launcher. When I click it the first time, I get a Exception in thread "AppKit Thread" java.lang.ExceptionInInitializerError. The second time I click it is when the NoClassDefFoundError shows up. Does this mean anything?

EDIT 2: Still trying to figure out this problem. I've possibly narrowed it down to an issue with Style. I don't know what that means, really, but the trace may help:

Caused by: java.lang.NullPointerException
    at com.sun.javafx.css.StyleManager.getURL(StyleManager.java:867)
    at com.sun.javafx.css.StyleManager.loadStylesheetUnPrivileged(StyleManager.java:1057)
    at com.sun.javafx.css.StyleManager.loadStylesheet(StyleManager.java:917)
    at com.sun.javafx.css.StyleManager._setDefaultUserAgentStylesheet(StyleManager.java:1377)
    at com.sun.javafx.css.StyleManager.setUserAgentStylesheets(StyleManager.java:1209)
    at com.sun.javafx.application.PlatformImpl.lambda$_setPlatformUserAgentStylesheet$182(PlatformImpl.java:698)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl._setPlatformUserAgentStylesheet(PlatformImpl.java:697)
    at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:548)
    at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:512)
    at javafx.scene.control.Control.<clinit>(Control.java:87)
    ... 6 more

I don't know how to follow past those ...6 more, but I can manually trace through to the JFX MenuBar class to find it in the MenuBar constructor: getStyleClass().setAll(DEFAULT_STYLE_CLASS); seems like a good candidate for where this is happening. I'm not sure how to proceed because this is in the .class file itself. Hopefully this helps.

EDIT 3: I was given the advice to just create a new workspace, check out the projects from SVN, and just start over. The thought was that maybe somehow the workspace was corrupted. Nothing changed; the exact same error has shown up. I am running out of ideas here.

EDIT 4: (thanks for the formatting, Itachi!) Here is what I can show, obscured:

package _______;

import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;

import ____.FooMenu;
import ____.FooMenuItem;
import ____.FooUtil;
import ____.FooVBox;
import ____.FooStates;

public class FooStageWithMenu extends FooStage
{
    private MenuBar menuBar;
    private FooMenu fileMenu;
    private FooVBox root;

    public FooStageWithMenu(FooStates setting, Image icon)
    {
        super();
        set(setting, icon);
        root = new FooVBox();

        menuBar = new MenuBar(); //This line is where it fails
        root.addNode(menuBar);
        /*...*/
    }
    /*...*/
}

A few other thoughts:

  • I'm developing on OSX, everyone I've spoken to on the project is using Windows. Could there be an OS-specific source of this problem?
  • We wanted to eliminate the possibility of library issues, so I installed the most recent version, now running JDK 1.8.0_102, problem still persists.
  • Is there some chance that even in the most recent JDK, there's some discrepancy between the jfxrt.jars in our respective libraries?
  • The nature of the specific error (see EDIT 2 above). It seems like there's an attempt to access a style sheet by retrieving a URL, but it either fails in accessing that style sheet, or in getting the URL, or something. Nothing about the NullPointerException seems to help me narrow it down past that. I did explore my jfxrt.jar and found that in the paths the JavaFX classes seem to be searching for, the .css files do exist and seem complete and non-corrupt.

EDIT 5: So I'm pretty sure nobody's reading this, but I did just find a big clue, related to the difference between this version and the previous. I don't think I need to get into the specifics, but this problem is "fixed" by commenting out one line in the launcher class. We have two launcher classes, one of which extends the other. The constructor for the extended class is just super(); new JFXPanel(); If I comment out the second line, it works without any immediately apparent problems. This might be the line that breaks it on a Mac, while it works fine in Windows. I have no idea what this implies, and I have no idea why the original failure I shared was caused by this. But this change is just made in a test branch, so it may be that we have no need to give this problem a proper fix, given the temporary and limited nature. I just wanted to share the update in case it helps anyone else.

Frank Harris
  • 587
  • 2
  • 16
  • Are you using Oracle JDK, or OpenJDK? – James_D Aug 04 '16 at 22:49
  • Looks like Oracle: `******$ java -version java version "1.8.0_77" Java(TM) SE Runtime Environment (build 1.8.0_77-b03) Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)` – Frank Harris Aug 05 '16 at 13:49
  • Can you add the code where MenuBar is getting initialized including the imports? – ItachiUchiha Aug 12 '16 at 15:16
  • It depends on a lot of proprietary classes, so I'm not sure what I can show. I'll see if I can give you an anonymized snippet. I also have a few more comments including elaboration on the Style issue, which seems to be central, according to the intuition of a colleague. – Frank Harris Aug 12 '16 at 18:04
  • A similar issue is with using JFreeChart-fx 1.0.1 with scalafx 8 on macOS 10.13.3. Running the main method in an object gave NPE in "AppKit thread" due to null ClassLoader in PrismFontLoader. (The calls went through ChartViewer and ChartCanvas.) The issue disappeared when launching from an object extending JFXApp. – schrödingcöder Mar 04 '18 at 18:05

0 Answers0