简体   繁体   中英

JDK 7/JavaFX 2 application on Mac OSX El Capitan

I've just upgraded to El Capitan and I'm running into problems starting a custom JavaFX2 application running under JDK1.7.0u79 (the latest available from Oracle).

When starting the app, I'm getting this Exception:

 Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
    at java.lang.Thread.run(Thread.java:745)
 Caused by: java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:191)
    at javafx.scene.control.Control.loadClass(Control.java:115)
    at javafx.scene.control.Control.loadSkinClass(Control.java:1021)
    at javafx.scene.control.Control.access$500(Control.java:70)
    at javafx.scene.control.Control$12.invalidated(Control.java:972)
    at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:127)
    at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:161)
    at com.sun.javafx.css.StyleableStringProperty.set(StyleableStringProperty.java:71)
    at javafx.scene.control.Control$12.set(Control.java:964)
    at com.sun.javafx.css.StyleableStringProperty.applyStyle(StyleableStringProperty.java:59)
    at com.sun.javafx.css.StyleableStringProperty.applyStyle(StyleableStringProperty.java:31)
    at com.sun.javafx.css.StyleableProperty.set(StyleableProperty.java:70)
    at com.sun.javafx.css.StyleHelper.transitionToState(StyleHelper.java:900)
    at javafx.scene.Node.impl_processCSS(Node.java:7418)
    at javafx.scene.Parent.impl_processCSS(Parent.java:1146)
    at javafx.scene.control.Control.impl_processCSS(Control.java:1154)
    at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
    at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
    at javafx.scene.Node.processCSS(Node.java:7386)
    at javafx.scene.Scene.doCSSPass(Scene.java:454)
    at javafx.scene.Scene.preferredSize(Scene.java:1468)
    at javafx.scene.Scene.impl_preferredSize(Scene.java:1535)
    at javafx.stage.Window$9.invalidated(Window.java:717)
    at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:127)
    at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:161)
    at javafx.stage.Window.setShowing(Window.java:781)
    at javafx.stage.Window.show(Window.java:796)
    at javafx.stage.Stage.show(Stage.java:233)
    at au.com.religaresecurities.trademax.client.Start.start(Start.java:131)
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
 Caused by: java.lang.NullPointerException
    at com.sun.t2k.MacFontFinder.initPSFontNameToPathMap(MacFontFinder.java:339)
    at com.sun.t2k.MacFontFinder.getFontNamesOfFontFamily(MacFontFinder.java:390)
    at com.sun.t2k.T2KFontFactory.getFontResource(T2KFontFactory.java:233)
    at com.sun.t2k.LogicalFont.getSlot0Resource(LogicalFont.java:184)
    at com.sun.t2k.LogicalFont.getSlotResource(LogicalFont.java:228)
    at com.sun.t2k.CompositeStrike.getStrikeSlot(CompositeStrike.java:86)
    at com.sun.t2k.CompositeStrike.getMetrics(CompositeStrike.java:132)
    at com.sun.javafx.font.PrismFontUtils.getFontMetrics(PrismFontUtils.java:31)
    at com.sun.javafx.font.PrismFontLoader.getFontMetrics(PrismFontLoader.java:466)
    at javafx.scene.text.Text.<init>(Text.java:153)
    at javafx.scene.text.Text.<init>(Text.java:162)
    at com.sun.javafx.scene.control.skin.ProgressIndicatorSkin.<clinit>(ProgressIndicatorSkin.java:78)
    ... 37 more

I can't just migrate the app to Java 8, so any help is much appreciated.

Update

I've been able to get the app running again by adding this to the start of my main method. Any better solutions out there?

    try {
        Class<?> macFontFinderClass = Class.forName("com.sun.t2k.MacFontFinder");
        Field psNameToPathMap = macFontFinderClass.getDeclaredField("psNameToPathMap");
        psNameToPathMap.setAccessible(true);
        psNameToPathMap.set(null, new HashMap<String, String>());
    } catch (Exception e) {
        // ignore
    }

After more than a week with that in an extensive enterprise application, I haven't noticed any problems in the UI.

For the lack of a better solution, I'm accepting my update above as answer. Maybe it helps someone...

I've been able to get the app running again by adding this to the start of my main method.

    try {
        Class<?> macFontFinderClass = Class.forName("com.sun.t2k.MacFontFinder");
        Field psNameToPathMap = macFontFinderClass.getDeclaredField("psNameToPathMap");
        psNameToPathMap.setAccessible(true);
        psNameToPathMap.set(null, new HashMap<String, String>());
    } catch (Exception e) {
        // ignore
    }

This isn't a direct answer, however I thought it important to pass on that this bug has been identified and fixed in an upcoming Java release. See https://bugs.openjdk.java.net/browse/JDK-8143907

I had the same problem. I changed the Text to a Label. I'm not sure it's possible in your case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM