Can't open a diferent window than default on JavaFX - javafx

The error log says that the function can't find the file ("Location is required"), and as far as I know, the fxml file name is right because it is in the same package as the main. I really don't know what to do because it works just fine with the sample fxml file created with the project.
package clfx;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class CLFX extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("MenuPrincipal.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
And the error log:
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: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$99(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
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.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at clfx.CLFX.start(CLFX.java:22)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$106(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$119(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$117(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$118(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$450(GtkApplication.java:139)
... 1 more
Exception running application clfx.CLFX
Java Result: 1

Related

JavaFX Gluon Progress Indicator using charm-glisten.jar For Desktop Application

I'm Trying to create a desktop application with circular progress indicator upon using gluon circular progress indicator using charm-glisten.jar file in scene builder I get InvocationTargetException while on using standard javafx-10 progress indicator it shows no Exception any suggestions ?.
Java Code:
package application;
import com.gluonhq.charm.glisten.control.ProgressIndicator;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
public class Main extends Application
{
private double xOffset = 0;
private double yOffset = 0;
#FXML
ProgressIndicator pg;
public void start(Stage primaryStage)
{
try
{
primaryStage.initStyle(StageStyle.TRANSPARENT);
AnchorPane root = FXMLLoader.load(getClass().getResource("Test1.fxml"));
Scene scene = new Scene(root,600,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
scene.setFill(javafx.scene.paint.Color.TRANSPARENT);
primaryStage.setScene(scene);
primaryStage.show();
root.setOnMousePressed(new EventHandler<MouseEvent>()
{
public void handle(MouseEvent e)
{
xOffset = e.getSceneX();
yOffset = e.getSceneY();
}
});
root.setOnMouseDragged(new EventHandler<MouseEvent>()
{
public void handle(MouseEvent e)
{
primaryStage.setX(e.getScreenX() - xOffset);
primaryStage.setY(e.getScreenY() - yOffset);
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
launch(args);
}
}
FXML Code:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.gluonhq.charm.glisten.control.ProgressIndicator?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: #3D4956;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Main">
<children>
<ProgressIndicator fx:id="pg" layoutX="196.0" layoutY="86.0" radius="100.0" />
</children>
</AnchorPane>
Error:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/css/converters/SizeConverter
at com.gluonhq.charm.glisten.control.ProgressIndicator.<clinit>(SourceFile:81)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404)
at java.base/java.lang.Class.newInstance(Class.java:591)
at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1019)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:754)
at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
at application.Main.start(Main.java:30)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Caused by: java.lang.ClassNotFoundException: com.sun.javafx.css.converters.SizeConverter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 29 more
Exception running application application.Main
enter image description here

Unsupported Operation Exception Java.Sql.Date [duplicate]

This question already has an answer here:
Convert between LocalDate and sql.Date [duplicate]
(1 answer)
Closed 4 years ago.
hello i need to display a date column in a tableview; in the database I declare the field fecha_nacimiento as date , i used a datepicker to insert that data into the database, so far its Ok with that operation so the next step was formatting the tableview cell to display the date data correctly, with the help of this site i did that, but when i need to retrieve the date data from the database i am getting an error, something like this:
Caused by: java.lang.UnsupportedOperationException
at java.sql.Date.toInstant(Unknown Source)
this is some of my controller code
public void initialize(URL arg0, ResourceBundle arg1) {
clienteid.setCellValueFactory(new PropertyValueFactory <Persona, Integer>("id_cliente"));
nombrescol.setCellValueFactory(new PropertyValueFactory <Persona, String>("nombres"));
apellidoscol.setCellValueFactory(new PropertyValueFactory <Persona, String>("apellidos"));
//fechacli.setCellValueFactory(new PropertyValueFactory <Persona, LocalDate>("fechacliente"));//
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
fechacli.setCellFactory(column -> {
return new TableCell<Persona, LocalDate>() {
#Override
protected void updateItem(LocalDate item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
} else {
setText(formatter.format(item));
}
}
};
});
seleccionaregistros();
seleccionanombre();
seleccionapellido();
}
public void seleccionaregistros() {
ObservableList <Persona> data =FXCollections.observableArrayList();
Connection conn=null;{
try {
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=prueba", "sa", "milkas87");
Statement mostrar=conn.createStatement();
ResultSet rs;
rs= mostrar.executeQuery("select * from cliente");
while ( rs.next() )
{
data.add(new Persona(
rs.getString("nombre"),
rs.getString("apellido"),
rs.getInt("id"),
rs.getDate(4).toInstant().atZone(ZoneId.systemDefault()).toLocalDate())
);
tablacliente.setItems(data);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
this is my persona class code
package application;
import java.time.LocalDate;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class Persona {
private StringProperty nombres;
private StringProperty apellidos;
private IntegerProperty id_cliente;
private ObjectProperty <LocalDate>fechacliente;
public Persona (String nombres, String apellidos, Integer id_cliente, LocalDate fechacliente) {
this.nombres= new SimpleStringProperty (nombres);
this.apellidos= new SimpleStringProperty ( apellidos);
this.id_cliente=new SimpleIntegerProperty (id_cliente);
this.fechacliente= new SimpleObjectProperty<>(fechacliente);
}
public LocalDate getFechaCliente() {
return fechacliente.get();
}
public void setFechaCliente(LocalDate fechacliente) {
this.fechacliente = new SimpleObjectProperty<>(fechacliente);
}
public ObjectProperty<LocalDate> fechaClienteProperty() {
return fechacliente;
}
public String getNombres() {
return nombres.get();
}
public void setNombres(String nombres) {
this.nombres=new SimpleStringProperty (nombres);
}
public String getApellidos() {
return apellidos.get();
}
public void setApellidos(String apellidos) {
this.apellidos=new SimpleStringProperty ( apellidos);
}
public Integer getId_cliente() {
return id_cliente.get();
}
public void setid_cliente(Integer id_cliente) {
this.id_cliente=new SimpleIntegerProperty (id_cliente);
}
}
id have been reading, and i found that can't truncate or pass the data beetween Localdate and Date, so any help could be truly helpful. regards.
all the errors here:
javafx.fxml.LoadException:
/C:/Users/ROA%20PC/eclipse-workspace/Conexion/bin/application/Vista.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
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.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at application.Main.start(Main.java:23)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsupportedOperationException
at java.sql.Date.toInstant(Unknown Source)
at application.ConexionController.seleccionaregistros(ConexionController.java:190)
at application.ConexionController.initialize(ConexionController.java:92)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 17 more
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
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$155(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Root cannot be null
at javafx.scene.Scene.<init>(Scene.java:336)
at javafx.scene.Scene.<init>(Scene.java:235)
at application.Main.start(Main.java:27)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
... 1 more
Exception running application application.Main
The java.sql.Date is a java.util.Date subclass that holds no time information, so you can’t convert it to an Instant class.
Fortunately, there is a toLocalDate method that does just that, convert it directly to LocalDate.
It should be like this:
rs.getDate(4).toLocalDate();
For further reference take a look at the JavaDoc https://docs.oracle.com/javase/8/docs/api/java/sql/Date.html#toInstant--

Exception thrown in main method in JavaFX

I'm facing some problems while executing my main function using javafx .It appears to be a problem in loading the fxml file if I'm not mistaken but I can't seem to find how to fix it .
Exception message:
Exception in Application start method java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)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$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at Gestion.view.MainClass.initialisationContenu(MainClass.java:57)
at Gestion.view.MainClass.start(MainClass.java:28)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
... 1 more
Exception running application Gestion.view.MainClass
Main function:
package Gestion.view;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class MainClass extends Application {
private Stage stagePrincipal;
private BorderPane conteneurPrincipal;
#Override
public void start(Stage primaryStage) {
stagePrincipal = primaryStage;
stagePrincipal.setTitle("Application de gestion du centre socio-médical OCP");
initialisationConteneurPrincipal();
initialisationContenu();
}
private void initialisationConteneurPrincipal() {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainClass.class.getResource("Welcome.fxml"));
try {
conteneurPrincipal = (BorderPane) loader.load();
Scene scene = new Scene(conteneurPrincipal);
stagePrincipal.setScene(scene);
stagePrincipal.show();
} catch (IOException e) {
e.printStackTrace();
}
}
private void initialisationContenu() {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass()
.getClassLoader()
.getResource("Acceuil1.fxml")
);
try {
AnchorPane conteneurPersonne = (AnchorPane) loader.load();
conteneurPrincipal.setCenter(conteneurPersonne);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
public Stage getStage() {
return null;
}
}
I've already searched in other similar questions , but the answers given did not work for me.
The problem is that FXMLLoader can't load an object hierarchy from FXML documents.
Fix it by updating the URLs:
loader.setLocation(MainClass.class.getResource("/fxml/Welcome.fxml"));
.getResource("/fxml/Acceuil1.fxml")
and moving Welcome.fxml and Acceuil1.fxml to src/main/resources/fxml directory.

Error in validation of JFXTextField

This is my first JavaFX program and I want to accept the username via eUser and password via ePass. When I try to check if the textfield is empty using validate I get this error:
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: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$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException:
file:/Users/dylan/NetBeansProjects/JavaFXApplication2/dist/run350595374/JavaFXApplication2.jar!/javafxapplication2/FXMLDocument.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
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.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at javafxapplication2.JavaFXApplication2.start(JavaFXApplication2.java:23)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.NullPointerException
at javafxapplication2.FXMLDocumentController.initialize(FXMLDocumentController.java:48)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 14 more
Exception running application javafxapplication2.JavaFXApplication2
Java Result: 1
When I comment out eUser.getValidators().add(vali); from Controller.java file and the lines that follow it, then no errors show up.
This is my FXMLDocumentController.java file:
public class FXMLDocumentController implements Initializable {
#FXML
private JFXTextField eUser;
#FXML
private JFXTextField ePass;
#FXML
private void handleClose(MouseEvent event) {
System.exit(0);
}
#Override
public void initialize(URL url, ResourceBundle rb) {
RequiredFieldValidator vali = new RequiredFieldValidator();
eUser.getValidators().add(vali);
vali.setMessage("No Input Given");
vali.focusedProperty().addListener(new ChangeListener<Boolean>(){
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if(!newValue)
{
eUser.validate();
}
}});}}
Main class:
public class JavaFXApplication2 extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
stage.initStyle(StageStyle.UNDECORATED);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Maybe this could be the problem. In your FXML file, check if you set those ID's to the relevant textfields. That might possibly be the thing which is causing the NullPointerException.
If you're using SceneBuilder, click on the relevant textfield -> Code and set the fx:id of those textFields.
And by the way, you can probably use a PasswordField instead of a TextField :)

Exception in Application start method java.lang.reflect.InvocationTargetException javafx

I write program with java8, JAVAFX, spring, hibernate, jpa, mysql.
I've to problem with connecting server part of program with javafx.
When I click on class with main→run as java aplication, this problems occurs:
log4j:WARN No appenders could be found for logger (org.jboss.resteasy.plugins.providers.DocumentProvider).
log4j:WARN Please initialize the log4j system properly.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/Sylwia/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Sylwia/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Sylwia/.m2/repository/org/slf4j/slf4j-simple/1.5.8/slf4j-simple-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$48/1732398722.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException:
/C:/Users/Sylwia/git/Praca%20inzynierska%203/Praca%20inzynierska%202/target/classes/fxml/productComponent.fxml
at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at pl.ftims.praca.restClientJavafx.RestClient.start(RestClient.java:17)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/1441419654.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/1051754451.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/742445343.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
... 1 more
Caused by: java.lang.NullPointerException
at pl.ftims.praca.restClientJavafx.FXMLController.initialize(FXMLController.java:140)
... 23 more
Exception running application pl.ftims.praca.restClientJavafx.RestClient
//////////////////////////////////////////////////////////////////////
Should I first focus on problem:
at pl.ftims.praca.restClientJavafx.RestClient.start(RestClient.java:17)
or:
Caused by: java.lang.NullPointerException
at pl.ftims.praca.restClientJavafx.FXMLController.initialize(FXMLController.java:140)
... 23 more
my RestClient class:
package pl.ftims.praca.restClientJavafx;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class RestClient extends Application {
#Override
public void start(Stage stage) throws Exception {
//When using the Class.getResource method,
//you must provide a local path from the location of the class on which is called the method.
//Parent root = FXMLLoader.load(RestClient.class.getResource("/fxml/components.fxml"));
Parent root = FXMLLoader.load(RestClient.class.getResource("/fxml/productComponent.fxml"));
//I also had to use Parent root = FXMLLoader.load(getClass().getResource("/fxml/Scene.fxml"));
/*FXMLLoader loader = new FXMLLoadergetClass().getResource("main.fxml");
loader.setController(new MainController(path));
Pane mainPane = loader.load();*/
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
FXMLController class
package pl.ftims.praca.restClientJavafx;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import pl.ftims.praca.model.ProductWrapper;
import pl.ftims.praca.model.Products;
public class FXMLController implements Initializable {
#FXML
private TableView productTable;
#FXML
private TableColumn idColumn;
#FXML
private TableColumn nameColumn;
#FXML
private TableColumn sellingPriceColumn;
#FXML
private TableColumn purchasePriceColumn;
#FXML
private TextField idField;//tego nie bylo chyba, bo nie mozna przeciez zmieniac id
#FXML
private TextField nameField;
#FXML
private TextField sellingPriceField;
#FXML
private TextField purchasePriceField;
/*private Long id;
private String name;
private Double sellingPrice;
private Double purchasePrice; //cena zakupu
#ManyToOne
private Storages storage; */
private List<Products> listOfProducts = null;
private List<Fxproduct> listOfFxProducts = null;
private ObservableList<Fxproduct> listOfObservableList = null;
private final static String REST_ROOT_URL = "http://localhost:8080/rest/";
private final Client client = ClientBuilder.newClient();
#FXML
private void remove(ActionEvent event) { //ok rozumiem
Fxproduct fxproduct = (Fxproduct) productTable.getSelectionModel().getSelectedItem();
listOfObservableList.remove(fxproduct);
Response response = client.target(REST_ROOT_URL).
// path("publisher").
path("products").
path("deleteProductWithId").
path(String.valueOf(fxproduct.getId())).
request().delete();
}
#FXML
private void save(ActionEvent event) {
Products product = new Products();
product.setName(nameField.getText());
product.setPurchasePrice(Double.parseDouble(purchasePriceField.getText()));
product.setSellingPrice(Double.parseDouble(sellingPriceField.getText()));
Entity<Products> kitapEntity = Entity.entity(product, MediaType.APPLICATION_XML);
Response response = client.target(REST_ROOT_URL).
path("product").
path("createProductWithData").
request().
post(kitapEntity);
list(null);
nameField.setText("");
purchasePriceField.setText("");
sellingPriceField.setText("");
}
#FXML
private void list(ActionEvent event) { //NIE WIEM JAK TO ZROBIC
Response response = client.target("http://localhost:8080/rest/").
path("products").
path("products").
request(MediaType.APPLICATION_XML).
get();
ProductWrapper productWrapper = response.readEntity(ProductWrapper.class); //nie mam tego
listOfProducts = (productWrapper.getProductList()==null)?new ArrayList<Products>(): productWrapper.getProductList();
// listOfFxProducts = new ArrayList<>();
// listOfFxProducts = new ArrayList<>(); //tak bylo, ale to jest java 1.7 i sie nie kompilowalo
for (Products k : listOfProducts) {
listOfFxProducts.add(new Fxproduct(k));
}
listOfObservableList = FXCollections.observableList(listOfFxProducts);
System.out.println(listOfObservableList);
productTable.setItems(listOfObservableList);
System.out.println(productTable);
}
public void kitapDuzenle(Products product) {
Entity<Products> kitapEntity = Entity.entity(product, MediaType.APPLICATION_XML);
Response response = client.target(REST_ROOT_URL).
path("product").
path("saveProduct2").
request().
put(kitapEntity);
}
// #SuppressWarnings("restriction")
#Override
public void initialize(URL url, ResourceBundle rb) {
productTable.setEditable(true); //tu jest blad, nullpointer
//NAME
nameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
nameColumn.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<Fxproduct, String>>() {
#Override
public void handle(TableColumn.CellEditEvent<Fxproduct, String> t) {
ObservableList<Fxproduct> kitapListesi = t.getTableView().getItems();
Fxproduct kitap = kitapListesi.get(t.getTablePosition().getRow());
kitap.setName(t.getNewValue());
kitapDuzenle(kitap.getproduct());
}
}
);
//SELLINGPRICE
sellingPriceColumn.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleToStringConverter()));//tu jest blad
sellingPriceColumn.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<Fxproduct, Double>>() {
#Override
public void handle(TableColumn.CellEditEvent<Fxproduct, Double> t) {
ObservableList<Fxproduct> kitapListesi = t.getTableView().getItems();
Fxproduct kitap = kitapListesi.get(t.getTablePosition().getRow());
kitap.setSellingPrice(t.getNewValue()); //tu ejst problem z double i siple double
kitapDuzenle(kitap.getproduct());
}
}
);
//PURCHASEPRICE
purchasePriceColumn.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleToStringConverter()));
purchasePriceColumn.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<Fxproduct, Double>>() {
#Override
public void handle(TableColumn.CellEditEvent<Fxproduct, Double> t) {
ObservableList<Fxproduct> kitapListesi = t.getTableView().getItems();
Fxproduct kitap = kitapListesi.get(t.getTablePosition().getRow());
kitap.setPurchasePrice(t.getNewValue());//tu ejst problem z double i siple double
kitapDuzenle(kitap.getproduct());
}
}
);
idColumn.setCellValueFactory(
new PropertyValueFactory<Fxproduct, Long>("id"));
nameColumn.setCellValueFactory(
new PropertyValueFactory<Fxproduct, String>("name"));
purchasePriceColumn.setCellValueFactory(
new PropertyValueFactory<Fxproduct, Double>("price"));
sellingPriceColumn.setCellValueFactory(
new PropertyValueFactory<Fxproduct, Double>("price"));
list(null);
}
}
I thought that the problems is the path:
Parent root = FXMLLoader.load(RestClient.class.getResource("/fxml/productComponent.fxml"));
but I read this:
How to reference javafx fxml files in resource folder?
JavaFX "Location is required." even though it is in the same package
Referencing class resource in FXML
Error loading fxml files from a folder other than the bin folder
JavaFX: load resource from other package - NetBeans
How to reference javafx fxml files in resource folder?
https://stackexchange.com/search?q=How+to+reference+javafx+fxml+files+in+resource+folder%3F
JavaFX - Exception in Application start method?
and I didnt find the answer.
/////////////////////////////EDIT///////////////////
line 17 in RestClient:
Parent root = FXMLLoader.load(RestClient.class.getResource("/fxml/productComponent.fxml"));
line 139, 140 in FXMLController:
public void initialize(URL url, ResourceBundle rb) { productTable.setEditable(true); // nullpointer

Resources