gpt4 book ai didi

java - JavaFX11 的 javafx.stage.Stage 版本无效

转载 作者:太空宇宙 更新时间:2023-11-04 10:09:42 27 4
gpt4 key购买 nike

我在新的 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 系统变量:

enter image description here

最佳答案

以防万一,您可以尝试添加 Stage 的 Maven 依赖项:

 <dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
</dependency>

Idea showing that dependency comes from the specified dependency

关于java - JavaFX11 的 javafx.stage.Stage 版本无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52511667/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com