我正在将 ScalaFX 与 Java 8 一起使用,并且在将 ScalaFX 提供给我们的 CSS 文件时遇到了困难。
到目前为止,我所阅读的所有内容都表明要使用以下内容:
object testObj extends JFXApp {
stage = new JFXApp.PrimaryStage {
scene = new Scene {
stylesheets += this.getClass.getResource("/css/app.css").toExternalForm
var nbutton = new Button("Submit")
content_=(List(nbutton))
}
}
}
如果我不费心尝试添加样式表,应用程序就会立即启动。但是,如果我确实尝试添加 css 文件,这就是我的控制台告诉我的:
[info] Running TestTool
Exception in Application start method
Workaround until RT-13281 is implemented: keep toolkit alive
[error] (run-main-0) java.lang.RuntimeException: Exception in Application start method
java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at TestTool$$anon$3$$anon$4.<init>(Main.scala:20)
at TestTool$$anon$3.<init>(Main.scala:19)
at TestTool$.delayedEndpoint$TestTool$1(Main.scala:14)
at TestTool$delayedInit$body.apply(Main.scala:13)
at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scalafx.application.JFXApp$class.scalafx$application$JFXApp$class$$$anonfun$2(JFXApp.scala:250)
at scalafx.application.JFXApp$class.scalafx$application$JFXApp$class$$$anonfun$2$adapted(JFXApp.scala:250)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
at scalafx.application.JFXApp$class.init(JFXApp.scala:250)
at TestTool$.init(Main.scala:13)
at scalafx.application.AppHelper.start(AppHelper.scala:32)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:745)
[trace] Stack trace suppressed: run last compile:run for the full output.
当然,应用程序没有启动。
到目前为止,我所阅读的所有内容都使它看起来像是 Java 8 的问题。我不知道从哪里开始。
任何帮助将不胜感激。
谢谢,