1

このリンク https://openjfx.io/openjfx-docs/#install-javafxの指示に従いました 。javafx サンプルを実行すると、このエラーが発生します。

Error:(3, 26) java: cannot access javafx.application.Application
  bad class file: C:\Program Files\Java\OpenJDK\javafx-sdk-11.0.1\lib\javafx.graphics.jar(javafx/application/Application.class)
    class file has wrong version 54.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.

Project Structure > Project/Modules に移動すると、JDK は JDK11 VM オプションに設定されます。

--module-path C:\Program Files\Java\OpenJDK\javafx-sdk-11.0.1\lib --add-modules=javafx.controls,javafx.fxml

Settings > Build, Execution, Deployment > Compiler > Java Compiler Project のバイトコードのバージョンを 8 に設定して 11 に変更すると、最初のエラーはなくなりましたが、新しいエラーが発生しました

Error:java: invalid target release: 11

私はインターネットで検索していましたが、誰か.idea\compiler.xmlがターゲットを 11 に設定すると言いましたが、すでに 11 に設定されていますが、エラーが発生します

4

2 に答える 2

1

ファイルに移動>プロジェクト構造>モジュール>ソース

言語レベルを 11 に設定します (11 が利用できない場合は、「X-Experimental Features」に設定します)

画像

于 2018-12-27T07:08:40.597 に答える
0

エラーが発生したばかりで、適切な解決策も見つからなかったので、自分で考え出しました。

問題の場所: pom.xml - maven ファイル

FXMLLoader や EventHandler など、さまざまな JavaFX エンティティで問題が発生することがあります。

  1. java: cannot access javafx.fxml.FXMLLoader bad class file: ... class file has wrong version 55.0, should be 53.0
  2. java: cannot access javafx.event.EventHandler bad class file: /Users/john/.m2/repository/org/openjfx/javafx-base/12/javafx-base-12-mac.jar!/javafx/event/EventHandler.class class file has wrong version 55.0, should be 53.0

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>hkr</groupId>
    <artifactId>CommunicationTest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>9</maven.compiler.source>
        <maven.compiler.target>9</maven.compiler.target>
    </properties>

不正解 (以前のバージョン):

<?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>hkr</groupId>
    <artifactId>CommunicationTest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

問題はプロパティタグにあります。ターゲット バージョンは JDK バージョン (9.0.1) 未満であり、私の場合は"class file has wrong version 55.0, should be 53.0".

1.8の代わりにターゲット 9に変更しただけで修正されました。

于 2021-04-23T01:25:06.793 に答える