FXML Initialize() throws InvocationTargetException

心不动则不痛 提交于 2020-01-07 08:23:27

问题


Im trying to set the text of a button on the initialize() method but it throws me InvocationTargetException, its the same if I try to get any items on the FXML.

FXML:

<VBox fx:id="vbox" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="450.0" spacing="40.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="instaj.LoginController">
   <children>
      <ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
         <image>
            <Image url="img/logo.png" />
         </image>
      </ImageView>
      <TextField id="user" maxWidth="200.0" prefHeight="35.0" promptText="Usuario" style="-fx-focus-color: #9a3bab; -fx-faint-focus-color: transparent;" />
      <javafx.scene.control.PasswordField id="pass" maxWidth="200.0" prefHeight="35.0" promptText="Contraseña" style="-fx-focus-color: #9a3bab; -fx-faint-focus-color: transparent;" />
      <Button fx:id="loginBtn" minHeight="30.0" minWidth="150.0" mnemonicParsing="false" onAction="#loginBtnBehavior" style="-fx-background-radius: 30; -fx-background-color: #9a3bab;" text="Iniciar" textFill="WHITE">
         <font>
            <Font size="16.0" />
         </font>
         <cursor>
            <Cursor fx:constant="HAND" />
         </cursor>
      </Button>
      <Label alignment="CENTER" onMouseClicked="#localAccountLinkBehavior" style="-fx-underline: true;" text="Iniciar con perfil abierto de Instagram dentro de Google Chrome." textFill="#0000ee">
         <cursor>
            <Cursor fx:constant="HAND" />
         </cursor>
      </Label>
   </children>
</VBox>

LoginController.java:

public class LoginController implements Initializable {

    @FXML
    Button loginBtn;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        Utils utils = new Utils();
        loginBtn.setText("test");
        //vbox.requestFocus();
        //utils.removeInitialFocus(user, vbox, firstTime);
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

回答1:


You ask your program to launch an Exception :

throw new UnsupportedOperationException("Not supported yet.");

So it's normal that it crashes : remove it !



来源:https://stackoverflow.com/questions/44899971/fxml-initialize-throws-invocationtargetexception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!