我正在使用最简单的示例尝试scalafx,但无法编译,并且错误如下:
I'm trying the scalafx with a simplest example, but it can't be compiled and the error is like:
错误:scalac:对类文件'StageIncludes.class'中遇到的javafx.stage.PopupWindow.AnchorLocation的错误符号引用. 无法访问对象javafx.stage.PopupWindow中的类型AnchorLocation.当前的类路径可能是 缺少javafx.stage.PopupWindow.AnchorLocation的定义,或StageIncludes.class可能已经针对以下版本进行了编译: 与当前类路径中找到的不兼容.
Error:scalac: bad symbolic reference to javafx.stage.PopupWindow.AnchorLocation encountered in class file 'StageIncludes.class'. Cannot access type AnchorLocation in object javafx.stage.PopupWindow. The current classpath may be missing a definition for javafx.stage.PopupWindow.AnchorLocation, or StageIncludes.class may have been compiled against a version that's incompatible with the one found on the current classpath.
我在Google上搜索,发现有人说我们需要将jfxrt.jar添加到类路径中,但是仍然无法正常工作.
I googled and found someone say we need to add the jfxrt.jar to classpath, but which is still not working.
我的代码:
build.sbt
name := "ColaBlog" version := "0.1.0" scalaVersion := "2.11.0" libraryDependencies ++= List( "org.scalafx" % "scalafx_2.11" % "8.0.0-R4" ) unmanagedJars in Compile += Attributed.blank( file(scala.util.Properties.javaHome) / "lib" / "jfxrt.jar") fork in run := trueApp.scala
import scalafx.Includes._ import scalafx.application.JFXApp import scalafx.scene.Scene import scalafx.scene.paint.Color import scalafx.scene.shape.Rectangle object App extends JFXApp { stage = new JFXApp.PrimaryStage { title = "Hello World" width = 600 height = 450 scene = new Scene { fill = Color.LIGHTGREEN content = Set(new Rectangle { x = 25 y = 40 width = 100 height = 100 fill <== when(hover) choose Color.GREEN otherwise Color.RED }) } } }仅此而已.
推荐答案这在Java 8 JVM上可以正常工作.可能的问题是您正在运行Java 7安装.
This works correctly on the Java 8 JVM. The likely problem is that you are running on a Java 7 install.
通过这些发行说明 ScalaFX具有两个并行发行版:
By these release notes ScalaFX has two parallel releases:
- v.1.0.0-支持JavaFX 2和Java 7(SFX-1)
- v.8.0.0-支持JavaFX 8和Java 8(SFX-8)
要么更新Java,要么使用另一个版本.
Either update Java, or use the other release.
更多推荐
最简单的scalafx示例无法编译
发布评论