0

First i'm new in JavaFX
i have build the project then i set " Run file " (Loader file ) to check if it's displaying the values from Derby database to a table , but i get this error output:

`init:
 Deleting: /home/isam/NetBeansProjects/Library Assistant/build/built- jar.properties
deps-jar:
Updating property file: /home/isam/NetBeansProjects/Library Assistant/build/built-jar.properties
Compiling 1 source file to /home/isam/NetBeansProjects/Library Assistant/build/classes

compile-single:
run-single:
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:/home/isam/NetBeansProjects/Library%20Assistant/dist/Library%20Assistant.jar!/library/assistant/ui/MemberList/member_list.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 library.assistant.ui.MemberList.member_list_Loader.start(member_list_Loader.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)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$48(GtkApplication.java:139)
... 1 more
Caused by: java.lang.NullPointerException
at library.assistant.ui.MemberList.Member_listController.loadData(Member_listController.java:71)
at library.assistant.ui.MemberList.Member_listController.initialize(Member_listController.java:55)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 17 more
Exception running application library.assistant.ui.MemberList.member_list_Loader
/home/isam/NetBeansProjects/Library Assistant/nbproject/build-impl.xml:1079: The following error occurred while executing this line:
/home/isam/NetBeansProjects/Library Assistant/nbproject/build-impl.xml:833: Java returned: 1
BUILD FAILED (total time: 1 second)

FXML file : member_list.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import java.net.URL?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane id="AnchorPane" fx:id="root" prefHeight="400.0" prefWidth="600.0" styleClass="mainFxmlClass" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="library.assistant.ui.MemberList.Member_listController">
   <stylesheets>
    <URL value="@member_list.css" />
</stylesheets>
   <children>
  <TableView fx:id="memberTable" prefHeight="400.0" prefWidth="600.0">
     <columns>
         <TableColumn fx:id="idColm" prefWidth="103.0" text="ID" />
         <TableColumn fx:id="nameColm" prefWidth="103.0" text="Nome" />
         <TableColumn fx:id="lastnameColm" prefWidth="107.0" text="Prénom" />
         <TableColumn fx:id="num_inscrptColm" prefWidth="128.0" text="N°inscrpt" />
         <TableColumn fx:id="spcialtyColm" prefWidth="158.0" text="Spécialité" />
       </columns>
      </TableView>
   </children>
</AnchorPane>

member_list_Loader.java

package library.assistant.ui.MemberList;

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;


public class member_list_Loader extends Application {

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("member_list.fxml"));

    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.show();
}


public static void main(String[] args) {
    launch(args);
}

}

Member_listController.java

package library.assistant.ui.MemberList;

import java.net.URL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import library.assistant.database.DatabaseHandler;
import library.assistant.ui.addBook.FXMLDocumentController;


public class Member_listController implements Initializable {

@FXML
 private TableView<Member> memberTable;
@FXML
private TableColumn<Member,String> idColm;
@FXML
private TableColumn<Member,String> nameColm;
@FXML
private TableColumn<Member,String> lastnameColm;
@FXML
private TableColumn<Member,String> num_inscrptColm;
@FXML
private TableColumn<Member,String> spcialtyColm;
// TableView<Book> table = new TableView();

 DatabaseHandler handler;
ObservableList<Member> list = FXCollections.observableArrayList();



@Override
public void initialize(URL url, ResourceBundle rb) {

    intCol();
    loadData();

}    

private void intCol() {
    nameColm.setCellValueFactory(new PropertyValueFactory<>("name"));
    idColm.setCellValueFactory(new PropertyValueFactory<>("id"));
    lastnameColm.setCellValueFactory(new PropertyValueFactory<>("lastname"));
    num_inscrptColm.setCellValueFactory(new PropertyValueFactory<>("num_inscrpt"));
    spcialtyColm.setCellValueFactory(new PropertyValueFactory<>("specialty"));
}

private void loadData(){

    String query = "SELECT * FROM MEMBRES";
    ResultSet rs = handler.execQuery(query);

    try {
        while(rs.next()){
            String id = rs.getString("id");
            String name = rs.getString("name");
            String lastname = rs.getString("lastname");
            String num_inscrpt = rs.getString("num_inscreption");
            String specialty = rs.getString("specialty");

            list.add(new Member(id, name, lastname, num_inscrpt, specialty));
        }
    } catch (SQLException ex) {
        Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
    }

    memberTable.getItems().setAll(list);

}

public static class Member{

    private final SimpleStringProperty id;
    private final SimpleStringProperty name;
    private final SimpleStringProperty lastname;
    private final SimpleStringProperty num_inscrpt;
    private final SimpleStringProperty specialty;

    public Member( String id, String name, String lastname, String num_inscrpt , String specialty) {
        this.id = new SimpleStringProperty(id);
        this.name = new SimpleStringProperty(name);
        this.lastname = new SimpleStringProperty(lastname);
        this.num_inscrpt = new SimpleStringProperty(num_inscrpt);
        this.specialty = new SimpleStringProperty(specialty);
    }

    public String getId() {
        return id.get();
    }

    public String getName() {
        return name.get();
    }

    public String getLastname() {
        return lastname.get();
    }

    public String getNum_inscrpt() {
        return num_inscrpt.get();
    }

    public String getSpecialty() {
        return specialty.get();

    }

}
}

i try to remove fx:controller from FXML file then i build and run loader file so i get the table window empty ( without values from database ) so i think the problem is in calling Controller from FXML, if it is so how i can call the Controller from loader file** ,or **if there is a solution related with calling from FXML it's better because i get this code from youtube and the coder has no problem with that .
But if there is another problem(s) please feel free to describe the solution i really care.
i run this in NetBeans IDE 8.2 , Fedora Linux 26 , if this related.

0 Answers0