java.lang.UnsupportedOperationException: Невозможно определить тип для свойства javafxml - PullRequest
0 голосов
/ 27 апреля 2018

Пытаюсь запустить мое приложение, но все, что я получил, это эта ошибка. Вот мой код, который, я считаю, является основной причиной. Этот тип ошибки является новым для меня, так как я впервые работаю с javafx, и я не вижу причины проблемы в списке ошибок. Main.java загрузчик

public class Main extends Application {



public void start(Stage primaryStage) {
    try {
        Parent root = FXMLLoader.load(getClass().getResource("/gui/ClientGui.fxml"));
        Scene scene = new Scene(root,622,588);
        scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
        primaryStage.setResizable(false);
        primaryStage.setScene(scene);
        primaryStage.show();
        primaryStage.setTitle("Denkibot - Laget med Dialogflow");

Контроллер

package controller;

import javafx.scene.control.Button;

public class FxControl {

    public Button sendBtn;

    public void sendMsg() {
        System.out.println("drep meg");
    }

}

Вот fxml , который, вероятно, является главной проблемой

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

<?import javafx.scene.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="588.0" prefWidth="622.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.FxControl">
   <children>
      <Pane prefHeight="400.0" prefWidth="600.0">
         <children>
            <MenuBar layoutY="2.0" prefHeight="25.0" prefWidth="634.0">
              <menus>
                <Menu mnemonicParsing="false" text="File">
                  <items>
                    <MenuItem mnemonicParsing="false" text="New Session" />
                        <MenuItem mnemonicParsing="false" text="Exit Application" />
                  </items>
                </Menu>
                <Menu mnemonicParsing="false" text="Options">
                  <items>
                    <MenuItem mnemonicParsing="false" text="Color" />
                  </items>
                </Menu>
                <Menu mnemonicParsing="false" text="About">
                  <items>
                    <MenuItem mnemonicParsing="false" text="Dialogflow" />
                        <MenuItem mnemonicParsing="false" text="Creators" />
                  </items>
                </Menu>
              </menus>
               <cursor>
                  <Cursor fx:constant="HAND" />
               </cursor>
            </MenuBar>
            <TextArea fx:id="chatWindow" editable="false" layoutX="25.0" layoutY="41.0" prefHeight="501.0" prefWidth="570.0" promptText="Velkommen til Denkibot Demo. Si &quot;Hallo&quot; for å starte en samtale.">
               <cursor>
                  <Cursor fx:constant="DEFAULT" />
               </cursor>
            </TextArea>
         </children>
      </Pane>
      <TextField fx:id="userInput" layoutX="25.0" layoutY="549.0" onKeyPressed="#sendMsg" prefHeight="25.0" prefWidth="512.0" promptText="Skriv meldingen her...">
         <cursor>
            <Cursor fx:constant="TEXT" />
         </cursor>
      </TextField>
      <Button fx:id="sendBtn" layoutX="548.0" layoutY="549.0" mnemonicParsing="false" onClick="#sendMsg" text="Send">
         <cursor>
            <Cursor fx:constant="HAND" />
         </cursor>
      </Button>
   </children>
   <cursor>
      <Cursor fx:constant="DEFAULT" />
   </cursor>
</AnchorPane>

Ошибка

javafx.fxml.LoadException:
/C:/Users/mariu/Desktop/Denkibot/samples/clients/text-client/target/classes/gui/ClientGui.fxml:54

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at gui.Main.start(Main.java:18)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsupportedOperationException: Cannot determine type for property.
    at com.sun.javafx.fxml.BeanAdapter.getSetterMethod(BeanAdapter.java:177)
    at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:250)
    at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:618)
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
    ... 17 more

1 Ответ

0 голосов
/ 27 апреля 2018

Вам нужно использовать onAction или onMouseClicked для кнопки вместо onClick.

Button не содержит свойства onClick.

<Button fx:id="sendBtn" layoutX="548.0" layoutY="549.0" mnemonicParsing="false" onAction="#sendMsg" text="Send">
    <cursor>
        <Cursor fx:constant="HAND" />
    </cursor>
</Button>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...