最简单的scalafx示例无法编译

编程入门 行业动态 更新时间:2024-10-08 13:38:36
本文介绍了最简单的scalafx示例无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用最简单的示例尝试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 := true

App.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示例无法编译

本文发布于:2023-11-28 08:04:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641589.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最简单   示例   scalafx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!