JavaFX代码无法在intellij-IDEA中正确编译。当我尝试构建应用程序时,它向我抛出了多个错误

时间:2018-10-19 08:27:38

标签: java intellij-idea javafx

我目前正在尝试创建javafx应用程序,当我在Intelli IDEA中尝试编译自动生成的代码时,我一直遇到错误。我目前也在运行JDK 11。

这是我在构建时遇到的错误:

 Error:(3, 26) java: package javafx.application does not exist
 Error:(4, 19) java: package javafx.fxml does not exist
 Error:(5, 20) java: package javafx.scene does not exist
 Error:(6, 20) java: package javafx.scene does not exist
 Error:(7, 20) java: package javafx.stage does not exist 
 Error:(9, 27) java: cannot find symbol
                 symbol: class Application
 Error:(12, 23) java: cannot find symbol
                   symbol:   class Stage
                   location: class sample.Main
 Error:(11, 5) java: method does not override or implement a method from a supertype
 Error:(13, 9) java: cannot find symbol
                 symbol:   class Parent
                 location: class sample.Main
 Error:(13, 23) java: cannot find symbol
                  symbol:   variable FXMLLoader
                  location: class sample.Main
 Error:(13, 39) java: cannot find symbol
                  symbol:   method getClass()
                  location: class sample.Main
 Error:(15, 35) java: cannot find symbol
                  symbol:   class Scene
                  location: class sample.Main
 Error:(21, 9) java: cannot find symbol
                  symbol:   method launch(java.lang.String[])
                  location: class sample.Main

这是我的代码

Main.java:

 package sample;

 import javafx.application.Application;
 import javafx.fxml.FXMLLoader;
 import javafx.scene.Parent;
 import javafx.scene.Scene;
 import javafx.stage.Stage;

 public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
    Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
    primaryStage.setTitle("Hello World");
    primaryStage.setScene(new Scene(root, 300, 275));
    primaryStage.show();
}


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

Controller.java:

 package sample;

 public class Controller {
 }

sample.fxml:

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

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.collections.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?scenebuilder-background-color 0xdae5ffff?>

  <AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" 
minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" 
prefWidth="600.0" 
xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<children>
    <ComboBox fx:id="trans_cb" blendMode="SRC_OVER" cache="false" 
disable="false" editable="false" layoutX="27.0" layoutY="47.0" 
mouseTransparent="false" prefHeight="21.000099999997474" prefWidth="150.0" 
promptText="SELECT">
        <items>
            <FXCollections fx:factory="observableArrayList">
                <String fx:value="i1" />
                <String fx:value="i2" />
                <String fx:value="i3" />
            </FXCollections>
        </items>
    </ComboBox>
     <Button layoutX="27.0" layoutY="139.0" mnemonicParsing="false" 
text="Generate" />
    <TextField layoutX="83.0" layoutY="14.0" prefWidth="71.0" />
    <TextField layoutX="208.0" layoutY="14.0" prefWidth="71.0" />
    <Label layoutX="27.0" layoutY="17.0" text="Channel" />
    <Label layoutX="169.0" layoutY="17.0" text="TPO" />
    <Label layoutX="284.0" layoutY="17.0" text="KW" />
    <CheckBox layoutX="192.0" layoutY="50.0" mnemonicParsing="false" 
text="Exciter" />
    <ComboBox layoutX="284.0" layoutY="48.0" prefHeight="21.0" 
prefWidth="125.0" promptText="Aux">
        <items>
            <FXCollections fx:factory="observableArrayList">
                <String fx:value="Item 1" />
                <String fx:value="Item 2" />
                <String fx:value="Item 3" />
            </FXCollections>
        </items>
    </ComboBox>
    <ComboBox layoutX="285.0" layoutY="77.0" prefHeight="21.0" 
prefWidth="124.0">
        <items>
            <FXCollections fx:factory="observableArrayList">
                <String fx:value="Item 1" />
                <String fx:value="Item 2" />
                <String fx:value="Item 3" />
            </FXCollections>
        </items>
    </ComboBox>
    <ComboBox layoutX="27.0" layoutY="78.0" prefHeight="21.0" 
prefWidth="150.0">
        <items>
            <FXCollections fx:factory="observableArrayList">
                <String fx:value="Item 1" />
                <String fx:value="Item 2" />
                <String fx:value="Item 3" />
            </FXCollections>
        </items>
    </ComboBox>
    <ComboBox layoutX="192.0" layoutY="79.0">
        <items>
            <FXCollections fx:factory="observableArrayList">
                <String fx:value="Item 1" />
                <String fx:value="Item 2" />
                <String fx:value="Item 3" />
            </FXCollections>
        </items>
    </ComboBox>
    <ComboBox layoutX="27.0" layoutY="108.0" prefHeight="21.0" 
prefWidth="150.0">
        <items>
            <FXCollections fx:factory="observableArrayList">
                <String fx:value="Item 1" />
                <String fx:value="Item 2" />
                <String fx:value="Item 3" />
            </FXCollections>
        </items>
    </ComboBox>
    <ComboBox layoutX="192.0" layoutY="108.0">
        <items>
            <FXCollections fx:factory="observableArrayList">
                <String fx:value="Item 1" />
                <String fx:value="Item 2" />
                <String fx:value="Item 3" />
            </FXCollections>
        </items>
    </ComboBox>
    <ComboBox layoutX="285.0" layoutY="108.0" prefHeight="21.0" 
prefWidth="124.0">
        <items>
            <FXCollections fx:factory="observableArrayList">
                <String fx:value="Item 1" />
                <String fx:value="Item 2" />
                <String fx:value="Item 3" />
            </FXCollections>
        </items>
    </ComboBox>
</children>
</AnchorPane>

0 个答案:

没有答案