FXML Initialize()抛出InvocationTargetException

时间:2017-07-04 07:47:25

标签: java javafx fxml

我试图在initialize()方法上设置一个按钮的文本,但是它会抛出InvocationTargetException,如果我尝试在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 个答案:

答案 0 :(得分:1)

您要求您的程序启动异常:

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

崩溃是正常的:删除它!

相关问题