简体   繁体   中英

JavaFx Invocation Target Expception

I wrote this simple program by creating a stylesheet with Scene Builder, but it doesn't works.

public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("Stile.fxml"));
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
}

And this is my .fxml file:

 <?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.StackPane?> <?import javafx.scene.control.ListView?> <?import javafx.geometry.Insets?> <StackPane prefHeight="355.0" prefWidth="402.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxml.esempio.mvc.ListController"> <children> <BorderPane prefHeight="304.0" prefWidth="0.0"> <bottom> <TextField id="testo" prefHeight="97.0" prefWidth="248.0" BorderPane.alignment="CENTER" /> </bottom> <left> <ScrollBar id="scrollbar" orientation="VERTICAL" BorderPane.alignment="CENTER" /> </left> <center> <ListView id="lista" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" /> </center> <top> <MenuBar id="barra" BorderPane.alignment="CENTER"> <menus> <Menu mnemonicParsing="false" text="File"> <items> <MenuItem mnemonicParsing="false" text="Close" /> </items> </Menu> <Menu mnemonicParsing="false" text="Edit"> <items> <MenuItem mnemonicParsing="false" text="Delete" /> </items> </Menu> <Menu mnemonicParsing="false" text="Help"> <items> <MenuItem mnemonicParsing="false" text="About" /> </items> </Menu> </menus> </MenuBar> </top> </BorderPane> </children> <padding> <Insets bottom="10" left="10" right="10" top="10" /> </padding> </StackPane> 

Do I need to add the elements singularly? If I wanna add controllers, how do I extract the single elements from the fxml?

In the fxml, you are declaring a Controller:

fx:controller="javafxml.esempio.mvc.ListController"

You just need to create it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM