运行示例文件时出现JavaFX错误

时间:2016-03-08 16:31:14

标签: java javafx

我尝试使用JavaFX从Oracle执行示例代码,我已经导入了该代码,但我仍然遇到同样的错误:

SEVERE: javafx.scene.control.Control loadSkinClass Failed to load skin 'StringProperty [bean: Button[id=null, styleClass=button], name: skinClassName, value: com.sun.javafx.scene.control.skin.ButtonSkin]' for control Button[id=null, styleClass=button]
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 com.sun.javafx.scene.control.skin.LabeledText.<init>(LabeledText.java:31)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.<init>(LabeledSkinBase.java:130)
    at com.sun.javafx.scene.control.skin.ButtonSkin.<init>(ButtonSkin.java:45)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at javafx.scene.control.Control.loadSkinClass(Control.java:1044)
    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.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 application.Main.start(Main.java:26)
    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)

SEVERE: javafx.scene.control.Control impl_processCSS The -fx-skin property has not been defined in CSS for Button[id=null, styleClass=button]
SEVERE: javafx.scene.control.Control impl_processCSS The -fx-skin property has not been defined in CSS for Button[id=null, styleClass=button]
SEVERE: javafx.scene.control.Control impl_processCSS The -fx-skin property has not been defined in CSS for Button[id=null, styleClass=button]
SEVERE: javafx.scene.control.Control impl_processCSS The -fx-skin property has not been defined in CSS for Button[id=null, styleClass=button]
SEVERE: javafx.scene.control.Control impl_processCSS The -fx-skin 

我的代码如下(所有示例内容):

package application;

import javafx.application.Application;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;


public class Main extends Application {

    public void start(Stage primaryStage) {

        try {
            StackPane root = new StackPane();
            Button btn = new Button("click here");
            root.getChildren().add(btn);


            Scene scene = new Scene(root);

            primaryStage.setScene(scene);
            primaryStage.setTitle("NICHE Robot");
            primaryStage.show();


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

    public static void main(String[] args) {
        launch(args);
    }
}

为什么我收到此错误?我在这个问题上搜索了每个人的问题,看起来这是FX版本的问题,所以我更新到了2.3。

我来自Java Swing背景,所以我不熟悉FX的所有配置细节,但是这个简单的程序似乎应该运行...

0 个答案:

没有答案