Java 无法将项目添加到组合框

Java 无法将项目添加到组合框,java,javafx,combobox,fxml,Java,Javafx,Combobox,Fxml,我试图通过FXML文件将项目添加到组合框中,但出现了此错误 javafx.fxml.LoadException: String is not a valid type. /C:/Users/kim/Desktop/JavaFX/ComboboxFx/bin/application/Main.fxml:13 at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source) at javafx.fxml.FXM

我试图通过FXML文件将项目添加到组合框中,但出现了此错误

    javafx.fxml.LoadException: String is not a valid type.
/C:/Users/kim/Desktop/JavaFX/ComboboxFx/bin/application/Main.fxml:13

    at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    at javafx.fxml.FXMLLoader.createElement(Unknown Source)
    at javafx.fxml.FXMLLoader.processStartElement(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at application.Main.start(Main.java:13)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
这是我的FXML

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

<?import javafx.collections.FXCollections?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="300.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" >
   <children>
      <ComboBox fx:id="comboBox">
        <items>
            <FXCollections fx:factory="observableArrayList">
                <String fx:value = "Gilbert" />
                <String fx:value = "John" />
            </FXCollections>
        </items>
      </ComboBox>
      <Label fx:id="selection" layoutX="34.0" layoutY="65.0" prefHeight="17.0" prefWidth="102.0" text="Label" />
   </children>
</AnchorPane>
当我通过场景生成器打开它时,会出现此错误

java.io.IOException: javafx.fxml.LoadException: Invalid attribute.
我已经仔细检查了所有东西,但代码似乎没问题。当我删除试图添加到FXML的值时,错误消失了,但我的组合框变为空。它说String不是有效的类型。我怎样才能解决这个问题?为什么它是无效的?我在这里检查了类似的问题,但是错误是由于没有导入FXCollections造成的。我导入了它,所以我认为错误不是由导入错误引起的

添加

到您的fxml

java.io.IOException: javafx.fxml.LoadException: Invalid attribute.