javaFX无法在JDK 10.0.1上运行

时间:2018-05-17 15:36:17

标签: java intellij-idea javafx

我试图在JDK10.0.1上运行javafx程序,但它导致了以下问题。

我的开发环境是win10 pro / intellij idea社区版2018.1.2 / oracle jdk 10.0.1

我的代码是

package LngToolAnalyzerFX.gui;

import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.net.URL;

public class Main extends Application {


    private MainUIController mainUICtr;
    @Override
    public void start(Stage primaryStage) throws Exception{
        String sceneFile = "UIconfig/MainUI.fxml";
        Parent root = null;
        URL    url  = null;

        url  = getClass().getClassLoader().getResource( sceneFile );
        FXMLLoader loader = new FXMLLoader(url);
        try
        {
            root = loader.load();
            System.out.println( "  fxmlResource = " + sceneFile );
            mainUICtr = loader.getController();
            mainUICtr.init();
        }
        catch ( Exception ex )
        {
            System.out.println( "Exception on FXMLLoader.load()" );
            System.out.println( "  * url: " + url );
            System.out.println( "  * " + ex );
            System.out.println( "    ----------------------------------------\n" );
            throw ex;
        }

        primaryStage.setTitle("LngToolAnalyzerFX");
        primaryStage.setScene(new Scene(root, 1024 , 768));

        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

,控制器类是

package LngToolAnalyzerFX.gui;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextArea;
import org.languagetool.JLanguageTool;
import org.languagetool.language.BritishEnglish;
import org.languagetool.rules.*;
import org.languagetool.tools.StringTools;

import java.util.List;


public class MainUIController {
    @FXML
    private Button checkBtn;
    private CheckBox onlineCheckBox;
    @FXML //fx:id="checkArea"
    private TextArea checkArea;
    @FXML//fx:id="resultArea"
    private TextArea resultArea;

    private String result;

    @FXML
    private void checkAction()
    {
        System.out.println("check");
        JLanguageTool lt = new JLanguageTool(new BritishEnglish());
        try
        {
            if(StringTools.isEmpty(checkArea.getText().trim()))
            {
                System.out.println("Please enter the text");
            }
            else
            {
                List<RuleMatch> matches = lt.check(checkArea.getText());

                resultArea.setText("");
                result = "";
                for (RuleMatch match : matches) {
                    result += "Potential error at characters \n" +
                            match.getFromPos() + "-" + match.getToPos() +
                            ":" + match.getMessage() + "\n";
                    result += "Suggested correction(s): " +
                                match.getSuggestedReplacements() + "\n\n";
                }
                resultArea.setText(result);
            }

        }
        catch(Exception ex)
        {
            System.out.println("----------------------");
            System.out.println(ex);
            System.out.println("----------------------");
        }
    }


    public void init()
    {
        //System.out.println("Hello");
        resultArea.setEditable(false);
        result = new String("");
    }

}

最后我得到了以下

的例外情况
Error:(4, 19) java: package javafx.fxml does not exist
Error:(8, 20) java: package javafx.stage does not exist
Error:(3, 26) java: package javafx.application does not exist
Error:(7, 20) java: package javafx.scene does not exist
Error:(5, 19) java: package javafx.fxml does not exist
Error:(6, 20) java: package javafx.scene does not exist

这是我的pom代码:

<?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>LngToolAnalyzer</groupId>
    <artifactId>LngToolAnalyzerFX</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <languagetool.version>4.1</languagetool.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
        <maven.jar.plugin>2.6</maven.jar.plugin>  <!-- NOTE: don't update without testing OpenOffice, 3.0.2 caused "Got no data stream!" after add-on installation -->
        <maven.assemby.plugin>2.6</maven.assemby.plugin>
        <junit.version>4.12</junit.version>
        <morfologik.version>2.1.5</morfologik.version>
        <jackson.version>2.9.4</jackson.version>
        <lucene.version>5.5.4</lucene.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.languagetool</groupId>
            <artifactId>languagetool-gui-commons</artifactId>
            <version>${languagetool.version}</version>
        </dependency>
        <dependency>
            <groupId>org.languagetool</groupId>
            <artifactId>languagetool-server</artifactId>
            <version>${languagetool.version}</version>
        </dependency>

        <dependency>
            <groupId>org.languagetool</groupId>
            <artifactId>languagetool-core</artifactId>
            <version>${languagetool.version}</version>
        </dependency>
        <dependency>
            <groupId>org.languagetool</groupId>
            <artifactId>language-all</artifactId>
            <version>${languagetool.version}</version>
        </dependency>


        <dependency>
            <groupId>org.carrot2</groupId>
            <artifactId>morfologik-tools</artifactId>
            <version>${morfologik.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.25</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>

        <!-- Some tests are used at runtime for rule developers, thus no 'test' scope here: -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.1</version>
        </dependency>

    </dependencies>

</project>

mainUI.fxml就在这里

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>

<GridPane alignment="center" hgap="10" vgap="10" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="LngToolAnalyzerFX.gui.MainUIController">
   <columnConstraints>
      <ColumnConstraints />
   </columnConstraints>
   <rowConstraints>
      <RowConstraints />
   </rowConstraints>
   <children>
      <AnchorPane prefHeight="480.0" prefWidth="640.0">
         <children>
            <Pane layoutX="28.0" layoutY="27.0" prefHeight="404.0" prefWidth="575.0">
               <children>
                  <SplitPane dividerPositions="0.5" orientation="VERTICAL" prefHeight="404.0" prefWidth="575.0">
                     <items>
                        <ScrollPane prefHeight="200.0" prefWidth="200.0">
                           <content>
                              <TextArea fx:id="checkArea" prefHeight="195.0" prefWidth="574.0" wrapText="true" />
                           </content>
                        </ScrollPane>
                        <ScrollPane prefHeight="200.0" prefWidth="200.0">
                           <content>
                              <TextArea fx:id="resultArea" prefHeight="195.0" prefWidth="574.0" wrapText="true" />
                           </content>
                        </ScrollPane>
                     </items>
                  </SplitPane>
               </children>
            </Pane>
            <Button fx:id="checKBtn" layoutX="28.0" layoutY="431.0" mnemonicParsing="false" onAction="#checkAction" text="check" />
            <CheckBox layoutX="530.0" layoutY="435.0" mnemonicParsing="false" text="CheckBox" />
         </children>
      </AnchorPane>
   </children>
</GridPane>

我已经将项目设置为jdk10.0.1,并将项目语言级别设置为&#34; 10&#34;在项目结构中,哈瓦我坐在环境中时会想念什么?但是,代码在jdk1.8中运行良好。

感谢任何检查我问题的人!

0 个答案:

没有答案