javafx 視窗載入的時候設定label拋出空指標異常
NULL
NULL 2018-09-27 11:40:25
0
0
1367

這是載入第二個窗體的程式碼

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

這是第二個窗體的顯示程式碼

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();
}

這是Message.fxml檔

<?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是世界上最好的语言

全部回覆(0)
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!