我正在Windows 10上运行,一些细节:
在这里我将字体更改为我的应用程序:
override val root = hbox{
menubar{
menu("File"){
item("Settings"){
style {
font = loadFont("app/assets/font/Ubuntu-L.ttf", 6.0)!!
}
}
}
}
}
调用loadFont()函数时引发错误。 这是堆栈跟踪:
kotlin.KotlinNullPointerException
at app.views.MenuBar$root$1$1$1$1$1.invoke(MenuBar.kt:20)
at app.views.MenuBar$root$1$1$1$1$1.invoke(MenuBar.kt:7)
at tornadofx.CSSKt.style(CSS.kt:1117)
at tornadofx.CSSKt.style$default(CSS.kt:1109)
at app.views.MenuBar$root$1$1$1$1.invoke(MenuBar.kt:19)
at app.views.MenuBar$root$1$1$1$1.invoke(MenuBar.kt:7)
at tornadofx.MenuKt.item(Menu.kt:148)
at tornadofx.MenuKt.item$default(Menu.kt:144)
at app.views.MenuBar$root$1$1$1.invoke(MenuBar.kt:18)
at app.views.MenuBar$root$1$1$1.invoke(MenuBar.kt:7)
at tornadofx.MenuKt.menu(Menu.kt:26)
at tornadofx.MenuKt.menu$default(Menu.kt:25)
at app.views.MenuBar$root$1$1.invoke(MenuBar.kt:17)
at app.views.MenuBar$root$1$1.invoke(MenuBar.kt:7)
at tornadofx.ControlsKt.menubar(Controls.kt:910)
at app.views.MenuBar$root$1.invoke(MenuBar.kt:15)
at app.views.MenuBar$root$1.invoke(MenuBar.kt:7)
at tornadofx.LayoutsKt.hbox(Layouts.kt:384)
at tornadofx.LayoutsKt.hbox$default(Layouts.kt:96)
at app.views.MenuBar.<init>(MenuBar.kt:14)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at java.base/java.lang.Class.newInstance(Class.java:560)
at tornadofx.FXKt.find(FX.kt:410)
at tornadofx.UIComponent.add(Component.kt:815)
at app.views.MainView$root$1.invoke(MainView.kt:15)
at app.views.MainView$root$1.invoke(MainView.kt:5)
at tornadofx.LayoutsKt.vbox(Layouts.kt:388)
at tornadofx.LayoutsKt.vbox$default(Layouts.kt:103)
at app.views.MainView.<init>(MainView.kt:6)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at java.base/java.lang.Class.newInstance(Class.java:560)
at tornadofx.FXKt.find(FX.kt:410)
at tornadofx.FXKt.find$default(FX.kt:399)
at tornadofx.App.start(App.kt:78)
at MyApp.start(main.kt:7)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
at java.base/java.lang.Thread.run(Thread.java:844)
经过一番搜索,我发现可以尝试在Windows上安装该字体,但是没有任何变化。