I got problem with my javaFx application. Everytime I call the .setText() method of my Label, I get a NullPointerException. Here is my code: This is a snnippet of my Controller:
public class HomenizerController implements Initializable{
//ArrayList zum abspeichern der Termine in Listen Form
private ArrayList<Date> dateList = new ArrayList();
//ArrayList zum ab speichern der Aufgaben in Listen Form
private ArrayList<ToDo> toDoList = new ArrayList();
private Properties prop = null;
@FXML private Label username;
private void setWelcomeTab(){
username.setText("A");
}
private void loadProperties(String path){
FileInputStream fis = null;
try {
prop = new Properties();
fis = new FileInputStream("src/homenizer/profiles/"+path+"/config.properties");
prop.load(fis);
} catch (FileNotFoundException ex) {
Logger.getLogger(HomenizerController.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(HomenizerController.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
if(fis != null)
fis.close();
} catch (IOException ex) {
Logger.getLogger(HomenizerController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public void startHomenizer(Stage stage, String username) throws IOException{
Parent root = FXMLLoader.load(getClass().getResource("/homenizer/view/HomenizerView.fxml"));
Scene scene = new Scene(root,1100,650);
stage.setResizable(true);
stage.setTitle("Homenizer");
stage.setScene(scene);
stage.show();
loadProperties(username);
setWelcomeTab();
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
And here is my .fxml:
<center>
<TabPane fx:id="tabPan">
<Tab text="Willkommen" closable="true" >
<VBox>
<TitledPane text="Allgemeines" expanded="true">
<GridPane>
<Label text="Benutzername:" GridPane.columnIndex="0" GridPane.rowIndex="0" />
<Label fx:id="username" GridPane.columnIndex="1" GridPane.rowIndex="0" />
<Label text="Termine gesamt:" GridPane.columnIndex="0" GridPane.rowIndex="1" />
<Label fx:id="dates" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Aufgaben gesamt:" GridPane.columnIndex="0" GridPane.rowIndex="2" />
<Label fx:id="toDos" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</GridPane>
</TitledPane>
<TitledPane text="Aktuell" expanded="true">
<GridPane fx:id="actualPane">
</GridPane>
</TitledPane>
</VBox>
</Tab>
</TabPane>
</center>
Everytime I want to set the Text of username I got this NULLPointerException:
Caused by: java.lang.NullPointerException
at homenizer.controller.HomenizerController.setWelcomeTab(HomenizerController.java:44)
at homenizer.controller.HomenizerController.startHomenizer(HomenizerController.java:76)
at homenizer.controller.LoginController.onStartRequest(LoginController.java:107)
... 54 more
Exception in thread "JavaFX Application Thread" Deleting directory C:\Users\chris_000\Documents\NetBeansProjects\Homenizer\dist\run1609603179
So, does anybody know the problem I got?I can't find a solution :( Thanks for every help
-GhostfaceChilla-