我在新的 Java SDK 11 中基于 this 创建了项目示例:
EntryPoint.java
package com.example;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Label;
public class EntryPoint extends javafx.application.Application {
public static void main (String[] args) {
launch();
}
public void start(Stage stage) {
Label label = new Label("Hello, JavaFX11!");
Scene scene = new Scene(label, 640, 480);
stage.setScene(scene);
stage.show();
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>Example</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
</dependencies>
</project>
IntelliJ IDEA 端没有警告。当我尝试编译时,出现错误(原文不是英文,因此可能与英文原文不同):
Error:(7, 20) java: Can not access to javafx.stage.Stage
Class C:\Users\XXXXX\.m2\repository\org\openjfx\javafx-graphics\11\javafx-graphics-11-win.
jar(javafx/stage/Stage.class) is invalid.
Class/File Version is 54.0; 52.0 is required.
Delete it, or set right directory.
更新
尝试设置 JAVA_HOME 系统变量:
最佳答案
以防万一,您可以尝试添加 Stage 的 Maven 依赖项:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
</dependency>
关于java - JavaFX11 的 javafx.stage.Stage 版本无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52511667/