JavaFX java.lang.reflect.InvocationTargetException (with scene builder) - java

I'm trying to make a program to Log in or register a person.
But I keep getting the same Exception.(InvocationTargetException)
Exception in Application start method
file:/C:/Users/Eigenaar/Desktop/p1g04/dist/SokobanGroep4.jar!/gui/StartScherm.fxml:19
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:363)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:303)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:875)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
at com.sun.javafx.application.LauncherImpl$$Lambda$48/1099983479.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at gui.StartSchermController.<init>(StartSchermController.java:73)
at StartUp.start(StartUp.java:27)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/2006606717.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/128893786.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/2063964656.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1108411398.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1147985808.run(Unknown Source)
... 1 more
Exception running application StartUp
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)
This is the code from my StartSchermController(the controller from my fxml file)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gui;
import domein.DomeinController;
import java.io.IOException;
import java.util.ArrayList;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField;
/**
* FXML Controller class
*
* #author Eigenaar
*/
public class StartSchermController extends SplitPane {
#FXML
private ChoiceBox chbTaal;
#FXML
private TextField txfMeldID;
#FXML
private TextField txfMeldWw;
#FXML
private TextField txfRegNaam;
#FXML
private TextField txfRegVNaam;
#FXML
private TextField txfRegWw2;
#FXML
private TextField txfRegWw;
#FXML
private TextField txfRegID;
#FXML
private Label lblMeldAan;
#FXML
private Label lblRegistreer;
#FXML
private Label lblMeldId;
#FXML
private Label lblMeldWw;
#FXML
private Label lblRegNaam,lblRegVNaam,lblRegId,lblRegWw,lblRegWw2;
private final DomeinController dc;
/**
* Initializes the controller class.
*/
public StartSchermController(DomeinController dc) {
this.dc=dc;
FXMLLoader loader=new FXMLLoader(getClass().getResource("StartScherm.fxml"));
loader.setRoot(this);
loader.setController(this);
try {
loader.load();
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
try{
chbTaal.setItems(FXCollections.observableArrayList(dc.keuzeTaal()));
} catch(NullPointerException e){
System.out.println(e.getMessage());
}
}
public int geefKeuze(){
int s = chbTaal.getSelectionModel().getSelectedIndex();
return s;
}
#FXML
private void actionchbTaal(ActionEvent event) {
int keuzeTaal = chbTaal.getSelectionModel().getSelectedIndex();
update(dc.setTaal(keuzeTaal));
this.geefKeuze();
}
private void update(ArrayList<String> s) {
lblMeldAan.setText(s.get(0));
this.lblMeldId.setText(s.get(1));
this.lblMeldWw.setText(s.get(2));
this.lblRegistreer.setText(s.get(3));
this.lblRegNaam.setText(s.get(4));
this.lblRegVNaam.setText(s.get(5));
this.lblRegId.setText(s.get(6));
this.lblRegWw.setText(s.get(7));
this.lblRegWw2.setText(s.get(8));
}
}
this is the code from my fxml file generated by JavaFX Scene Builder 2.0
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<fx:root dividerPositions="0.19095477386934673" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" type="SplitPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="148.0" prefWidth="598.0">
<children>
<Label layoutX="384.0" layoutY="21.0" text="SOKOBAN" textFill="#d7300f">
<font>
<Font name="Colonna MT" size="24.0" />
</font>
</Label>
<ComboBox fx:id="chbTaal" layoutX="37.0" layoutY="24.0" onAction="#actionchbTaal" prefWidth="150.0" />
</children></AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<SplitPane dividerPositions="0.481421647819063" layoutY="-6.0" prefHeight="331.0" prefWidth="621.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<Label fx:id="lblMeldAan" layoutX="12.0" layoutY="1.0" prefHeight="27.0" prefWidth="106.0">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="lblMeldId" layoutX="14.0" layoutY="42.0" prefHeight="17.0" prefWidth="74.0" />
<TextField fx:id="txfMeldID" layoutX="97.0" layoutY="38.0" />
<Label fx:id="lblMeldWw" layoutX="14.0" layoutY="83.0" prefHeight="17.0" prefWidth="74.0" />
<TextField fx:id="txfMeldWw" layoutX="97.0" layoutY="79.0" />
<TextField layoutX="30.0" layoutY="165.0" prefHeight="116.0" prefWidth="244.0" />
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<Label fx:id="lblRegistreer" layoutX="14.0" layoutY="1.0" prefHeight="27.0" prefWidth="106.0">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="lblRegNaam" layoutX="82.0" layoutY="41.0" text="Naam:" />
<Label fx:id="lblRegWw" layoutX="51.0" layoutY="148.0" text="Wachtwoord:" />
<Label fx:id="lblRegId" layoutX="51.0" layoutY="112.0" text="GebruikersID:" />
<Label fx:id="lblRegVNaam" layoutX="58.0" layoutY="76.0" text="Voornaam:" />
<Label fx:id="lblRegWw2" layoutX="8.0" layoutY="185.0" text="Controle Wachtwoord:" />
<TextField fx:id="txfRegNaam" layoutX="128.0" layoutY="37.0" />
<TextField fx:id="txfRegVNaam" layoutX="128.0" layoutY="72.0" />
<TextField fx:id="txfRegWw2" layoutX="128.0" layoutY="181.0" />
<TextField fx:id="txfRegWw" layoutX="128.0" layoutY="144.0" />
<TextField fx:id="txfRegID" layoutX="128.0" layoutY="108.0" />
</children>
</AnchorPane>
</items>
</SplitPane>
</children></AnchorPane>
</items>
</fx:root>
And this is the code from my domeinController where the code to set the language set.(The choice for a language is done with resourcebundels)
import java.util.ArrayList;
import java.util.Locale;
import java.util.ResourceBundle;
public class DomeinController {
public ArrayList<String> keuzeTaal(){
ArrayList<String> taal = new ArrayList<>();
taal.add("Nederlands");
taal.add("Français");
taal.add("English");
return taal;
}
public ArrayList<String> setTaal(int i){
ResourceBundle taal=Taal(i);
ArrayList<String> s= new ArrayList<>();
s.add(taal.getString("meldAan"));
s.add(taal.getString("gebruikersID"));
s.add(taal.getString("wachtwoord"));
s.add(taal.getString("registreer"));
s.add(taal.getString("naam"));
s.add(taal.getString("voornaam"));
s.add(taal.getString("gebruikersID"));
s.add(taal.getString("wachtwoord"));
s.add(taal.getString("herhalingWachtwoord"));
return s;
}
public static ResourceBundle Taal(int taalKeuze) {
Locale locale;
ResourceBundle taal;
if (taalKeuze==1) {
locale = Locale.FRENCH;
} else if (taalKeuze==2) {
locale = Locale.ENGLISH;
} else {
locale = new Locale("nl");
}
return ResourceBundle.getBundle("taal\\LabelsBundle", locale);
}
;
}
Thank you in advance. I hope somebody can help me. (sorry for my bad english)

Your controller is declaring chTaal as a ChoiceBox but your FXML is declaring it as a ComboBox. The FXMLLoader can't coerce a conversion between those types so it doesn't set chTaal to anything, leaving it as null. Make the types match in the two files and see if that corrects your issue.

Related

FXML Exception error while running my code

This is my main inside application package:
package application;
import java.net.URL;
import javax.swing.JOptionPane;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import model.Model;
public class Main extends Application {
Parent root;
Scene scene;
#Override
public void start(Stage primaryStage) {
try {
URL url = getClass().getResource("/view/AddCustomer.fxml");
root = FXMLLoader.load(url);
scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(e -> {
int save = JOptionPane.showConfirmDialog(null, "Do you want to save changes in the product table?");
if (save == 0) {
Model.getInstance().SaveCustomers();
Model.getInstance().SaveSessions();
Model.getInstance().SaveAdministrators();
Model.getInstance().SaveCoachs();
}
System.exit(0);
});
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
This is my addCustomerController inside controller package:
package controller;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
public class AddCustomerController {
#FXML
private Button cancelMemberButton;
#FXML
private Pane customerPane;
#FXML
private RadioButton dailyMemberType;
#FXML
private TextField memberDiscountField;
#FXML
private RadioButton memberFemaleButton;
#FXML
private TextField memberIdField;
#FXML
private RadioButton memberMaleButton;
#FXML
private TextField memberMobileField;
#FXML
private TextField memberNameField;
#FXML
private TextField memberNationalityField;
#FXML
private RadioButton monthlyMemberType;
#FXML
private Button saveMemberButton;
#FXML
private RadioButton yearlyMemberType;
#FXML
void cancelButtonClick(ActionEvent event) {
}
#FXML
void saveButtonClick(ActionEvent event) {
}
}
This is the FXML file inside view package(Its called AddCustomer.fxml):
<?xml version="1.0" encoding="UTF-8"?>
<?import com.gluonhq.charm.glisten.control.ToggleButtonGroup?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<Pane fx:id="customerPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="532.0" prefWidth="789.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.AddCustomerController">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="258.0" layoutY="34.0" prefHeight="41.0" prefWidth="274.0" text="Add Customer" textFill="#860b0b">
<font>
<Font name="Arial" size="37.0" />
</font>
</Label>
<Separator layoutY="98.0" prefHeight="1.0" prefWidth="789.0" style="-fx-background-color: #860b0b;">
<opaqueInsets>
<Insets />
</opaqueInsets>
</Separator>
<Label layoutX="27.0" layoutY="144.0" prefHeight="23.0" prefWidth="103.0" text="Member ID" />
<Label layoutX="27.0" layoutY="195.0" prefHeight="23.0" prefWidth="103.0" text="Name" />
<Label layoutX="27.0" layoutY="243.0" prefHeight="23.0" prefWidth="103.0" text="Mobile" />
<Label layoutX="27.0" layoutY="296.0" prefHeight="23.0" prefWidth="103.0" text="Nationality" />
<Label layoutX="27.0" layoutY="345.0" prefHeight="23.0" prefWidth="103.0" text="Gender" />
<Label layoutX="27.0" layoutY="394.0" prefHeight="23.0" prefWidth="103.0" text="MemberShip Type" />
<Label layoutX="27.0" layoutY="440.0" prefHeight="23.0" prefWidth="103.0" text="Discount" />
<TextField fx:id="memberIdField" layoutX="246.0" layoutY="143.0" prefHeight="30.0" prefWidth="486.0" />
<TextField fx:id="memberNameField" layoutX="246.0" layoutY="194.0" prefHeight="25.0" prefWidth="486.0" />
<TextField fx:id="memberMobileField" layoutX="246.0" layoutY="242.0" prefHeight="25.0" prefWidth="486.0" />
<TextField fx:id="memberNationality" layoutX="246.0" layoutY="295.0" prefHeight="25.0" prefWidth="486.0" />
<RadioButton fx:id="memberMaleButton" layoutX="341.0" layoutY="348.0" mnemonicParsing="false" text="Male" />
<RadioButton fx:id="memberFemaleButton" layoutX="412.0" layoutY="348.0" mnemonicParsing="false" text="Female" />
<RadioButton fx:id="dailyMemberType" layoutX="341.0" layoutY="397.0" mnemonicParsing="false" text="Daily" />
<RadioButton fx:id="monthlyMemberType" layoutX="412.0" layoutY="397.0" mnemonicParsing="false" text="Monthly" />
<RadioButton fx:id="yearlyMemberType" layoutX="499.0" layoutY="397.0" mnemonicParsing="false" text="Yearly" />
<TextField fx:id="discountField" editable="false" layoutX="246.0" layoutY="439.0" prefHeight="25.0" prefWidth="486.0" />
<Button fx:id="saveMemberButton" layoutX="246.0" layoutY="482.0" mnemonicParsing="false" onAction="#saveButtonClick" prefHeight="30.0" prefWidth="164.0" text="Save" />
<Button fx:id="cancelMemberButton" layoutX="499.0" layoutY="482.0" mnemonicParsing="false" onAction="#cancelButtonClick" prefHeight="30.0" prefWidth="164.0" text="Cancel" />
<ToggleButtonGroup layoutX="130.0" layoutY="170.0" selectionType="SINGLE" />
</children>
</Pane>
This is the error I get when run my main:
javafx.fxml.LoadException:
/C:/Users/ADMIN/eclipse-workspace/Project_V2_V2/bin/view/AddCustomer.fxml
at javafx.fxml#19/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2707)
at javafx.fxml#19/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2949)
at javafx.fxml#19/javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2793)
at javafx.fxml#19/javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2758)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2624)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3331)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3287)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3255)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3227)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3203)
at javafx.fxml#19/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3196)
at Project_V2_V2/application.Main.start(Main.java:22)
at javafx.graphics#19/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics#19/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics#19/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics#19/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics#19/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics#19/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics#19/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.ClassNotFoundException: com.gluonhq.charm.glisten.control.ToggleButtonGroup
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:3017)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:3006)
at javafx.fxml#19/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2947)
... 20 more
I searched online for problems, i found all of the issues that has been offered online are not similar to mine at least from what i understood. I fixed some things that were in my code. However, it still did not solve the issue for me. Please i need help fixing this issue.
You are using Gluons com.gluonhq.charm.glisten.control.ToggleButtonGroup from their mobile tooling. Do you really want to do that? Maybe using the standard JavaFX ToggleGroup would be sufficient. If you really want to use Gluons lib then you have to add this implementation 'com.gluonhq:charm-glisten:6.2.2' to your dependencies. But note, that glisten is a proprietary offering with a different license than JavaFX.

JavaFX control spinner dont works

Hi I'd like add to control "Spinner" integers between 1 to 24. I write my function and i added to fxml file but display exception (JavaFX 11).
Normally while I build window display spinner with default value "7" i can also change int from 1 to 24 but with each click display this exception.
Summarizing,
addChangeVIEW.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="305.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.controller.addChangeController">
<children>
<Button fx:id="addChangeButton" graphicTextGap="8.0" layoutX="413.0" layoutY="110.0" mnemonicParsing="false" prefHeight="85.0" prefWidth="128.0" text="ADD CHANGE" textAlignment="CENTER" textFill="#e50a0a" textOverrun="LEADING_WORD_ELLIPSIS" />
<DatePicker fx:id="dateChangePicker" layoutX="23.0" layoutY="138.0" />
<Label fx:id="descDatePicker" layoutX="70.0" layoutY="100.0" prefHeight="18.0" prefWidth="89.0" text="Date Change">
<font>
<Font size="14.0" />
</font>
</Label>
<Label fx:id="fromHourLabel" layoutX="215.0" layoutY="99.0" text="From Hour" />
<Label fx:id="toHourLabel" layoutX="311.0" layoutY="99.0" text="To Hour" />
<Label fx:id="statusLabel" layoutX="83.0" layoutY="216.0" prefHeight="33.0" prefWidth="258.0" text="WAIT FOR ADD CHANGE" textFill="#14f004">
<font>
<Font name="Arial" size="18.0" />
</font>
</Label>
<Spinner fx:id="fromHourSpinner" layoutX="214.0" layoutY="137.0" onMouseClicked="#spinnersAction" prefHeight="26.0" prefWidth="58.0" />
<Spinner fx:id="toHourSpinner" accessibleText="1" layoutX="303.0" layoutY="137.0" onMouseClicked="#spinnersAction" prefHeight="26.0" prefWidth="58.0" />
</children>
</AnchorPane>
addChangeController
package com.controller;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import java.net.URL;
import java.util.ResourceBundle;
public class addChangeController implements Initializable {
#FXML
private Spinner<Integer> fromHourSpinner;
#FXML
private Spinner<Integer> toHourSpinner;
SpinnerValueFactory<Integer> spinner = new SpinnerValueFactory.IntegerSpinnerValueFactory(1,24,7);
#FXML
public void spinnersAction(ActionEvent event){
//fromHourSpinner.setValueFactory(spinner);
}
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
fromHourSpinner.setValueFactory(spinner);
}
}
Init
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch
Process finished with exit code 0
As i have same problem, So here is the solution i found
Just need to rearrange the code a little bit like this..
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
SpinnerValueFactory<Integer> spinner =new SpinnerValueFactory.IntegerSpinnerValueFactory(1,24,7);
fromHourSpinner.setValueFactory(spinner);
toHourSpinner.setValueFactory(spinner);
}

FXML Load exception when inserting data of own class into tableview

I have a problem again.
I am trying to understand FXML and I am currently using the "Mastering FXML" guide of oracle "creating an address book with FXML".
I am pretty near at the end of the guide but i am not able to fix a problem I have since yesterday.
I want to write a Maintenance Program for my father but I am always getting the statement:javafx.fxml.LoadException: Maintenance is not a valid type.
there are 3 classes that are important for this problem I guess. That would be my "mainLayout.fxml", "FXMLDocumentController.java" and "Maintenance.java"
So I am just posting them in this order
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import javafx.collections.*?>
<Pane fx:controller="FXMLDocumentController" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="858.0" prefWidth="1276.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<SplitPane dividerPositions="0.8687747035573122" layoutX="2.0" layoutY="25.0" prefHeight="839.0" prefWidth="1276.0">
<items>
<AnchorPane fx:id="anchorpaneLeft" minHeight="0.0" minWidth="0.0" prefHeight="811.0" prefWidth="1104.0">
<children>
<ScrollPane id="scrollpane" fx:id="scrollpane" layoutX="452.0" layoutY="319.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<TableView id="tableView" fx:id="tableView" prefHeight="834.0" prefWidth="1102.0">
<columns>
<TableColumn text="%tablecolumnName" >
<cellValueFactory><PropertyValueFactory property = "name"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="%tablecolumnAddress" >
<cellValueFactory><PropertyValueFactory property = "address"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="%tablecolumnNumber" >
<cellValueFactory><PropertyValueFactory property = "number"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="%tablecolumnMail" >
<cellValueFactory><PropertyValueFactory property = "mail"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="%tablecolumnLast" >
<cellValueFactory><PropertyValueFactory property = "last"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="%tablecolumnNext" >
<cellValueFactory><PropertyValueFactory property = "next"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="%tablecolumnNote" >
<cellValueFactory><PropertyValueFactory property = "note"/>
</cellValueFactory>
</TableColumn>
</columns>
<items>
<FXCollections fx:factory="observableArrayList">
<Maintenance name="jacob" address="fichtestraße 5" number="01515242" mail="jacob#jacob.com" last="10.10.2018" next="10.10.2019" note="leer jung"/>
</FXCollections>
</items>
</TableView>
</content>
</ScrollPane>
</children>
</AnchorPane>
<AnchorPane fx:id="anchorpaneRight" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<VBox fx:id="vboxNew" alignment="TOP_CENTER" layoutX="50.0" layoutY="52.0" prefHeight="85.0" prefWidth="164.0" spacing="15.0" AnchorPane.bottomAnchor="726.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="26.0">
<children>
<Label fx:id="labelNew" prefHeight="17.0" prefWidth="192.0" text="%labelNew">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
<Button fx:id="buttonInsert" mnemonicParsing="false" prefHeight="25.0" prefWidth="100.0" text="%buttonInsert" onAction="#handleInsertButton" textAlignment="CENTER" />
</children>
</VBox>
<VBox fx:id="vboxEdit" alignment="TOP_CENTER" layoutY="120.0" prefHeight="717.0" prefWidth="164.0" spacing="15.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="120.0">
<children>
<Label fx:id="labelEdit" prefHeight="17.0" prefWidth="166.0" text="%labelEdit">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
<Button fx:id="buttonEdit" alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="25.0" prefWidth="100.0" text="%buttonEdit" textAlignment="CENTER" />
<Button fx:id="buttonDelete" mnemonicParsing="false" prefHeight="25.0" prefWidth="100.0" text="%buttonDelete" />
<Button fx:id="buttonWeek" mnemonicParsing="false" prefHeight="25.0" prefWidth="100.0" text="%buttonWeek" />
<Button fx:id="buttonMonth" mnemonicParsing="false" prefHeight="25.0" prefWidth="100.0" text="%buttonMonth" />
<Button fx:id="buttonYear" alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="25.0" prefWidth="100.0" text="%buttonYear" />
</children>
</VBox>
</children>
</AnchorPane>
</items>
</SplitPane>
<MenuBar fx:id="menubar" layoutX="2.0" layoutY="2.0" prefHeight="25.0" prefWidth="1276.0">
<menus>
<Menu fx:id="menuFile" mnemonicParsing="false" text="%menuFile">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu fx:id="menuEdit" mnemonicParsing="false" text="%menuEdit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu fx:id="menuHelp" mnemonicParsing="false" text="%menuHelp">
<items>
<MenuItem fx:id="itemAbout" mnemonicParsing="false" text="%itemAbout" />
</items>
</Menu>
<Menu fx:id="menuLanguage" mnemonicParsing="false" text="%menuLanguage">
<items>
<MenuItem fx:id="itemGer" mnemonicParsing="false" text="%itemGer" />
<MenuItem fx:id="itemEng" mnemonicParsing="false" text="%itemEng" />
</items>
</Menu>
</menus>
</MenuBar>
</children>
</Pane>
FXMLDocumentController.java:
import java.net.URL;
import java.util.*;
import javafx.collections.*;
import javafx.event.*;
import javafx.fxml.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.stage.*;
public class FXMLDocumentController implements Initializable {
#FXML private Label label;
#FXML private TableView<Maintenance> table;
#FXML private TableColumn tablecolumnName;
#FXML private TableColumn tablecolumnAddress;
#FXML private TableColumn tablecolumnNumber;
#FXML private TableColumn tablecolumnMail;
#FXML private TableColumn tablecolumnLast;
#FXML private TableColumn tablecolumnNext;
#FXML private TableColumn tablecolumnNote;
#FXML private Button buttonInsert;
#FXML private Button buttonEdit;
#FXML private Button buttonDelete;
#FXML private Button buttonWeek;
#FXML private Button buttonMonth;
#FXML private Button buttonYear;
#FXML private TextField textfieldName;
#FXML private TextField textfieldAddress;
#FXML private TextField textfieldMail;
#FXML private TextField textfieldNumber;
#FXML private TextField textfieldLast;
#FXML private TextField textfieldNext;
#FXML private TextField textfieldNote;
#FXML private TableView<Maintenance> tableView;
#FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
label.setText("Hello World!");
}
#Override
public void initialize(URL url, ResourceBundle rb) {
}
#FXML
void handleInsertButton(ActionEvent event){
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("insertWindow.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setTitle("Insert Window");
Scene scene = new Scene (root1);
stage.setScene(scene);
stage.show();
} catch(Exception e){
e.printStackTrace();
}
}
protected void handleEditButton() {
}
protected void handleDeleteButton() {
}
protected void handleWeekButton() {
}
protected void handleMonthButton() {
}
protected void handleYearButton() {
}
protected void handleGerButton() {
}
protected void handleEngButton() {
}
#FXML
protected void addMaintenance(ActionEvent event){
ObservableList <Maintenance> data = tableView.getItems();
data.add(new Maintenance(textfieldName.getText(), textfieldAddress.getText(),
textfieldMail.getText(), textfieldNumber.getText(),
textfieldLast.getText(), textfieldNext.getText(),
textfieldNote.getText()));
textfieldName.setText("");
textfieldAddress.setText("");
textfieldMail.setText("");
textfieldNumber.setText("");
textfieldLast.setText("");
textfieldNext.setText("");
textfieldNote.setText("");
}
}
and finally Maintenance.java
import javafx.beans.property.SimpleStringProperty;
public class Maintenance {
private final SimpleStringProperty name = new SimpleStringProperty("");
private final SimpleStringProperty address = new SimpleStringProperty("");
private final SimpleStringProperty number = new SimpleStringProperty("");
private final SimpleStringProperty mail = new SimpleStringProperty("");
private final SimpleStringProperty last = new SimpleStringProperty("");
private final SimpleStringProperty next = new SimpleStringProperty("");
private final SimpleStringProperty note = new SimpleStringProperty("");
public Maintenance(){
this("", "", "", "", "", "", "");
}
public Maintenance(String name, String address, String number, String mail, String last, String next, String note){
setName(name);
setAddress(address);
setNumber(number);
setMail(mail);
setLast(last);
setNext(next);
setNote(note);
}
public String getName() {
return name.get();
}
public String getAddress() {
return address.get();
}
public String getNumber() {
return number.get();
}
public String getMail() {
return mail.get();
}
public String getLast() {
return last.get();
}
public String getNext() {
return next.get();
}
public String getNote() {
return note.get();
}
public final void setName(String Name){
name.set(Name);
}
public final void setAddress(String Address){
address.set(Address);
}
public final void setNumber(String Number){
number.set(Number);
}
public final void setMail(String Mail){
mail.set(Mail);
}
public final void setLast(String Last){
last.set(Last);
}
public final void setNext(String Next){
next.set(Next);
}
public final void setNote(String Note){
note.set(Note);
}
}
insertwindow.fxml is existing and worked great so far so I won't post it to shorten my post same for main.java and my 4 property files.
Hope someone can tell me what I am doing wrong again.
Thanks for help!
Executing C:\Users\Schurke\Documents\NetBeansProjects\Maintenance\dist\run365389303\Maintenance.jar using platform D:\Program Files\Java\jdk1.8.0_202\jre/bin/java
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$159(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException:
file:/C:/Users/Schurke/Documents/NetBeansProjects/Maintenance/dist/run365389303/Maintenance.jar!/mainLayout.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2848)
at javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2692)
at javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2661)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2517)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3116)
at Main.start(Main.java:19)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$166(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$179(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
... 1 more
Caused by: java.lang.ClassNotFoundException
at javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2899)
at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2846)
... 19 more
Exception running application Main
Java Result: 1
For custom FXML type you should add an import statement:
<?import Maintenance?>
In general it is bad practice to use default packages. Put the Maintenance.java into some package and import it as:
<?import yourPackageName.Maintenance?>

JAVAFX javafx.fxml.LoadException simple login page

Getting LoadExeption evertime i try to run this code.
the code ran fine the first time but after that i just keep getting this error.
Its just a simple login page with not much coding what so ever.
Main class below
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
Parent root=FXMLLoader.load(getClass().getResource("/application/Login.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args); // tried changing this to string[0] didnt work
}
}
Main controller class below i wanted to add more sql stuff to this but i keep getting the same error.
In this i am just trying to change
package application;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import javafx.fxml.FXML;
public class MainController {
#FXML
private Label LblStatus;
#FXML
private TextField TxtUsername;
#FXML
private TextField TxtPassword;
public void Login(ActionEvent event)
{
LblStatus.setText("Login sucsess");
}
}
login page
All of this was created using scene builder and youtube.
so i basically have no idea why i am getting this error.
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="400.0" prefWidth="500.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="application.MainController">
<!-- TODO Add Nodes -->
<children>
<Pane prefHeight="400.0" prefWidth="500.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<TitledPane animated="false" layoutX="0.0" layoutY="0.0" prefHeight="400.0000999999975" prefWidth="500.0" text="LOGIN FORM" textAlignment="CENTER" wrapText="false">
<content>
<AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextField fx:id="TxtUsername" layoutX="227.0" layoutY="129.0" prefWidth="200.0" promptText="Enter Username" />
<Label layoutX="129.0" layoutY="129.0" prefWidth="98.0" text="USERNAME:">
<font>
<Font size="15.0" fx:id="x1" />
</font>
</Label>
<Label font="$x1" layoutX="129.0" layoutY="183.0" prefWidth="98.0" text="PASSWORD:" />
<Button font="$x1" layoutX="224.0" layoutY="225.0" mnemonicParsing="false" onAction="#Login" text="LOGIN" />
<PasswordField fx:id="TxtPassword" layoutX="224.0" layoutY="183.0" prefWidth="200.0" promptText="Enter Password" />
<Label id="Status" fx:id="LblStatus" layoutX="259.0" layoutY="69.0" text="Status">
<font>
<Font size="20.0" />
</font>
</Label>
</children>
</AnchorPane>
</content>
<font>
<Font name="Arial Black" size="15.0" />
</font>
</TitledPane>
</children>
</Pane>
</children>
</AnchorPane>
You have the wrong imports in your controller. Replace
import java.awt.Label;
with
import javafx.scene.control.Label ;
etc...

JavaFx java.lang.NullPointerException with scene builder 2.0

I'm trying to make a program to Log in or register a person. But I am getting the Exception.(InvocationTargetException and the NullPointerException)
Error Stack Trace
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:363)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:303)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:875)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
at com.sun.javafx.application.LauncherImpl$$Lambda$48/1099983479.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at gui.StartSchermController.<init>(StartSchermController.java:81)
at StartUp.start(StartUp.java:27)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/93724165.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/128893786.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/2063964656.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1108411398.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1147985808.run(Unknown Source)
... 1 more
Exception running application StartUp
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
I have problem with this line.
chTaal.setItems(FXCollections.observableArrayList(dc.keuzeTaal()));
StartSchermController.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gui;
import domein.DomeinController;
import java.io.IOException;
import java.util.ArrayList;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField;
/**
* FXML Controller class
*
* #author Eigenaar
*/
public class StartSchermController extends SplitPane {
#FXML
private TextField txfMeldID;
#FXML
private TextField txfMeldWw;
#FXML
private TextField txfRegNaam;
#FXML
private TextField txfRegVNaam;
#FXML
private TextField txfRegWw2;
#FXML
private TextField txfRegWw;
#FXML
private TextField txfRegID;
#FXML
private Label lblMeldAan;
#FXML
private Label lblRegistreer;
#FXML
private Label lblMeldId;
#FXML
private Label lblMeldWw;
#FXML
private Label lblRegNaam,lblRegVNaam,lblRegId,lblRegWw,lblRegWw2;
#FXML
private Button btnMeldAan,btnRegistreer;
private final DomeinController dc;
#FXML
private ComboBox cmbTaal;
#FXML
private TextField txfStartExc;
/**
* Initializes the controller class.
* #param dc
*/
public StartSchermController(DomeinController dc) {
this.dc=dc;
FXMLLoader loader=new FXMLLoader(getClass().getResource("StartScherm.fxml"));
loader.setRoot(this);
loader.setController(this);
try {
loader.load();
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
cmbTaal.setItems(FXCollections.observableArrayList(dc.keuzeTaal()));
}
public int geefKeuze(){
int s = cmbTaal.getSelectionModel().getSelectedIndex();
return s;
}
#FXML
private void cmbTaalOnAction(ActionEvent event) {
int keuzeTaal = cmbTaal.getSelectionModel().getSelectedIndex();
System.out.println(keuzeTaal);
updateTaal(dc.setTaal(keuzeTaal));
this.geefKeuze();
}
private void updateTaal(ArrayList<String> s) {
lblMeldAan.setText(s.get(0));
this.lblMeldId.setText(s.get(1));
this.lblMeldWw.setText(s.get(2));
this.lblRegistreer.setText(s.get(3));
this.lblRegNaam.setText(s.get(4));
this.lblRegVNaam.setText(s.get(5));
this.lblRegId.setText(s.get(6));
this.lblRegWw.setText(s.get(7));
this.lblRegWw2.setText(s.get(8));
}
#FXML
private void btnMeldAanOnAction(ActionEvent event){
String id= this.txfMeldID.getText();
String ww= this.txfMeldWw.getText();
try{
dc.meldAan(id, ww);
}catch(Exception e){
txfStartExc.setText(e.getMessage());
this.txfMeldID.setText("");
this.txfMeldWw.setText("");
}
this.txfMeldID.setText("");
this.txfMeldWw.setText("");
}
#FXML
private void btnRegistreerOnAction(ActionEvent event){
String n=this.txfRegNaam.getText();
String vn=this.txfRegVNaam.getText();
String id= this.txfRegID.getText();
String ww= this.txfRegWw.getText();
String ww2=this.txfRegWw2.getText();
dc.maakSpelerAan(n, vn, id, ww);
}
}
this is the code from my fxml file generated by JavaFX Scene Builder 2.0
StartScherm.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<fx:root dividerPositions="0.17839195979899497" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" type="SplitPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gui.StartSchermController">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<Label layoutX="352.0" text="SOKOBAN" textFill="#d7300f">
<font>
<Font name="Colonna MT" size="48.0" />
</font>
</Label>
<ComboBox fx:id="cmbTaal" layoutX="46.0" layoutY="18.0" onAction="#cmbTaalOnAction" prefWidth="150.0" />
</children></AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="257.0" prefWidth="598.0">
<children>
<SplitPane dividerPositions="0.481421647819063" layoutY="-8.0" prefHeight="400.0" prefWidth="621.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="346.0" prefWidth="295.0">
<children>
<Label fx:id="lblMeldAan" layoutX="12.0" layoutY="1.0" prefHeight="27.0" prefWidth="106.0">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="lblMeldId" layoutX="14.0" layoutY="42.0" prefHeight="17.0" prefWidth="74.0" />
<TextField fx:id="txfMeldID" layoutX="97.0" layoutY="38.0" />
<Label fx:id="lblMeldWw" layoutX="14.0" layoutY="83.0" prefHeight="17.0" prefWidth="74.0" />
<TextField fx:id="txfMeldWw" layoutX="97.0" layoutY="79.0" />
<TextField fx:id="txfStartExc" layoutX="26.0" layoutY="184.0" prefHeight="116.0" prefWidth="244.0" />
<Button fx:id="btnMeldAan" layoutX="97.0" layoutY="129.0" mnemonicParsing="false" onAction="#btnMeldAanOnAction" text="Meld aan" />
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<Label fx:id="lblRegistreer" layoutX="14.0" layoutY="1.0" prefHeight="27.0" prefWidth="106.0">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="lblRegNaam" layoutX="8.0" layoutY="41.0" prefHeight="17.0" prefWidth="113.0" text="" />
<Label fx:id="lblRegWw" layoutX="8.0" layoutY="148.0" prefHeight="17.0" prefWidth="113.0" text="" />
<Label fx:id="lblRegId" layoutX="8.0" layoutY="112.0" prefHeight="17.0" prefWidth="113.0" text="" />
<Label fx:id="lblRegVNaam" layoutX="8.0" layoutY="76.0" prefHeight="17.0" prefWidth="113.0" text="" />
<Label fx:id="lblRegWw2" layoutX="8.0" layoutY="185.0" text="" />
<TextField fx:id="txfRegNaam" layoutX="128.0" layoutY="37.0" />
<TextField fx:id="txfRegVNaam" layoutX="128.0" layoutY="72.0" />
<TextField fx:id="txfRegWw2" layoutX="128.0" layoutY="181.0" />
<TextField fx:id="txfRegWw" layoutX="128.0" layoutY="144.0" />
<TextField fx:id="txfRegID" layoutX="128.0" layoutY="108.0" />
<Button fx:id="btnRegistreer" layoutX="128.0" layoutY="226.0" mnemonicParsing="false" onAction="#btnRegistreerOnAction" text="Registreer" />
</children>
</AnchorPane>
</items>
</SplitPane>
</children></AnchorPane>
</items>
</fx:root>
DomeinController.java
package domein;
import java.util.ArrayList;
import java.util.Locale;
import java.util.ResourceBundle;
public class DomeinController {
private final SpelerRepository spelerRepository;
private Speler speler;
// private Spel spel;
public DomeinController() {
spelerRepository = new SpelerRepository();
}
/*
public void registreer(String naam, String voornaam, String email, LocalDate geboortedatum, String wachtwoord, String wachtwoordBevestiging) {
if (!wachtwoord.equals(wachtwoordBevestiging)) {
throw new EmailException();
}*/
/*
Speler nieuweSpeler = new Speler(naam, voornaam, gebruikersID, wachtwoord);
setSpeler(nieuweSpeler); // ONTBREEKT!!
spelerRepository.voegToe(nieuweSpeler);
}*/
/** UC_1 meldAan DOING */
public void meldAan(String gebruikersID, String wachtwoord) {
Speler gevondenSpeler = spelerRepository.meldAan(gebruikersID, wachtwoord);
if (gevondenSpeler != null) {
setSpeler(gevondenSpeler);
}
}
/** UC_1 meldAan KNOWING */
public String[] geefDetailsSpeler() {
return speler.geefDetailsSpeler();
/* if (speler == null) {
return null;
}
String[] spelerS = new String[3];
spelerS[0] = speler.getVoornaam();
spelerS[1] = speler.getNaam();
return spelerS;*/
}
private void setSpeler(Speler speler){
this.speler = speler;
}
public void maakSpelerAan(String naam, String voornaam, String gebruikersID, String wachtwoord) {
Speler s=new Speler(naam,voornaam,gebruikersID,wachtwoord,false);
spelerRepository.voegToe(s);
}
public ArrayList<String> keuzeTaal(){
ArrayList<String> taal = new ArrayList<>();
taal.add("Nederlands");
taal.add("Français");
taal.add("English");
return taal;
}
public ArrayList<String> setTaal(int i){
ResourceBundle taal=setResourceBundle(i);
ArrayList<String> s= new ArrayList<>();
s.add(taal.getString("meldAan"));
s.add(taal.getString("userID"));
s.add(taal.getString("wachtwoord"));
s.add(taal.getString("registreer"));
s.add(taal.getString("naam"));
s.add(taal.getString("voornaam"));
s.add(taal.getString("userID"));
s.add(taal.getString("wachtwoord"));
s.add(taal.getString("herhalingWachtwoord"));
return s;
}
public static ResourceBundle setResourceBundle(int taalKeuze) {
Locale locale=null;
ResourceBundle taal;
if (taalKeuze==1) {
locale = Locale.FRENCH;
} else if (taalKeuze==2) {
locale = Locale.ENGLISH;
} else if(taalKeuze==0) {
locale = new Locale("nl");
}
return ResourceBundle.getBundle("taal\\LabelsBundle", locale);
}
;
}
/*
private void setSpel(Spel spel) {
this.spel = spel;
}
*/
Main Class StartUp.java
import domein.DomeinController;
import gui.StartSchermController;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.scene.Scene;
import javafx.stage.Stage;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* #author Eigenaar
*/
#SuppressWarnings("unchecked")
public class StartUp extends Application
{
#Override
#SuppressWarnings("unchecked")
public void start(Stage stage)
{
DomeinController controller = new DomeinController();
StartSchermController root = new StartSchermController(controller);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Startscherm Sokoban");
stage.show();
}
public static void main(String[] args)
{
launch(args);
}
}
Thank you in advance. I hope somebody can help me.
I don't think your FXML is loading. Add a System.exit(1); to the catch block after you call loader.load(); to check.
If you use loader.setController(...), you should not have a fx:controller attribute in the FXML file. Remove that attribute, and it should fix the problem.

Categories