Setting label when javafx window is loading throws null pointer exception
NULL
NULL 2018-09-27 11:40:25
0
0
1442

This is the code to load the second form

public void ToLogin() throws IOException {
    Message msg = new Message();
    msg.show("登录失败");
}

This is the display code of the second form

public void show(String message) throws IOException {
    Parent root = FXMLLoader.load(Message.class.getResource("Message.fxml"));
    Scene scene = new Scene(root);
    stage.setScene(scene);
    label.setText(message);//此处抛出空指针异常
    stage.initStyle(StageStyle.TRANSPARENT);
    stage.show();
}

This is the Message.fxml file

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

<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<?import javafx.scene.control.Button?>
<AnchorPane prefHeight="150.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Message.Message">
    <Label fx:id="tips" alignment="CENTER" prefHeight="30.0" prefWidth="400.0" stylesheets="@Message.css" text="提示" textAlignment="CENTER" textFill="WHITE">
      <font>
         <Font size="19.0" />
      </font></Label>
    <Label
        alignment="CENTER"
        textAlignment="CENTER"
        stylesheets="@Message.css"
        fx:id="label"
        prefHeight="40.0"
        prefWidth="400.0"
        layoutY="50.0"
    >
    </Label>
    <Button
            prefWidth="100.0"
            prefHeight="30.0"
            text="确定"
            fx:id="Sure"
            layoutX="80.0"
            layoutY="110.0"
            onAction="#Yes"
    >
    </Button>
    <Button
            prefWidth="100.0"
            prefHeight="30.0"
            text="确定"
            fx:id="Chanl"
            layoutX="230.0"
            layoutY="110.0"
            onAction="#No"
    >
    </Button>
</AnchorPane>


NULL
NULL

PHP是世界上最好的语言

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template