【问题标题】:FXML Initialize() throws InvocationTargetExceptionFXML Initialize() 抛出 InvocationTargetException
【发布时间】:2017-07-04 07:47:24
【问题描述】:

我试图在 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.");
    }
}

【问题讨论】:

  • 从初始化方法中移除throw new UnsupportedOperationException("Not supported yet.");
  • @MBec 正在工作,谢谢!!

标签: java javafx fxml


【解决方案1】:

你要求你的程序启动一个异常:

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

所以它崩溃是正常的:删除它!

【讨论】:

  • 显然,当您在netbeans中实现初始化方法时,这行代码会自动添加,我没有注意到,谢谢azro!
  • @DiegoBarrena 是的,当你开始编写方法时删除它;)
猜你喜欢
  • 1970-01-01
  • 2019-09-11
  • 2017-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-23
相关资源
最近更新 更多