Problem z wczytaniem pliku FXML przy uruchomieniu aplikacji

Odpowiedz Nowy wątek
2019-01-05 21:11
Wielki Szewc
0

Podczas uruchamiania aplikacji pojawia się problem z wczytaniem pliku FXML. Pojawia się w linijce z fxmlloader klasy KontoBankowe. Pliki .fxml oraz .java mam w folderze z src\kontobankowe (standard w NetBeans src\nazwa-pakietu )
Kontrolerem dla Logowanie.fxml jest klasa Administrator, w której mam zdefiniowanie kontrolki oraz funkcje zaloguj zmieniającą panel logowania na panel administratora.
Pliki fxml generowanie przez Scene Builder.


public class KontoBankowe extends Application {

    @Override
    public void start(Stage stage) throws Exception {

        Parent root = FXMLLoader.load(getClass().getResource("Logowanie.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

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

}
public void zaloguj(ActionEvent event) throws Exception {

        if(checkAdmin.isSelected()){
            if(txtLogin.getText().equals(login) && txtHasloLogowania.getText().equals(haslo)){

                Stage adminStage = new Stage();
                Parent root = FXMLLoader.load(getClass().getResource("Administrator.fxml"));
                Scene scene = new Scene(root);
                adminStage.setScene(scene);
                adminStage.show();

            }else{
                status.setText("Logowanie nie powiodło się!");
            }
        }

Pozostało 580 znaków

2019-01-05 22:40
0

Podczas uruchamiania aplikacji pojawia się problem z wczytaniem pliku FXML.

A jaki?

edytowany 1x, ostatnio: Berylo, 2019-01-05 22:40

Pozostało 580 znaków

2019-01-05 23:30
Wielki Szewc
0

Problem zażegnany :D
Temat do zamknięcia.

Pozostało 580 znaków

2019-01-06 23:07
Wielki Szewc
0

Jednak pojawił się nowy podobny problem. Zainspirowany projektem:

https://github.com/JaretWright/GUIDemo/tree/master/src/guidemo

Chciałbym wyświetlić w TableView ObservableList z klasy Bank. MenuController zmienia sceny i przechodzi do logowania admina bądź klienta. KontoBankowe to kontroler dla logowania administratora i klienta. Po zalogowaniu administrator chce mieć podgląd kont bankowych za pomocą TableView, jednak program zwraca masę błędów już w Menu. Gdy operowałem na polach typu String lista nie wyświetlała się, ale wyświetlanie okien logowania i samo logowanie przebiegało bez problemu tzn gdy usunę metodę initialize z KontoBankowe i zamienię pola z SimpleStringProperty na String.

package kontobankowe;

import java.io.IOException;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class MenuController {

    @FXML private Button btnWyjscie;

    public void pokazLogowanieKlienta (ActionEvent event) throws IOException{

        Parent logowanieWidok = FXMLLoader.load(getClass().getResource("FXMLLogowanieKlient.fxml"));
        Scene scene = new Scene(logowanieWidok);

        //This line gets the Stage information
        Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
        window.setScene(scene);
        window.show();
    }

    public void pokazLogowanieAdministratora (ActionEvent event) throws IOException{

        Parent logowanieWidok = FXMLLoader.load(getClass().getResource("FXMLLogowanieAdministrator.fxml"));
        Scene scene = new Scene(logowanieWidok);

        //This line gets the Stage information
        Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
        window.setScene(scene);
        window.show();
    }

    public void zamknijAplikacje (ActionEvent event) throws IOException{

        Stage stage = (Stage)btnWyjscie.getScene().getWindow();

        stage.close();
    }
}
package kontobankowe;

import javafx.beans.property.SimpleStringProperty;

public class Konto {

    private SimpleStringProperty imie;
    private SimpleStringProperty nazwisko;
    private SimpleStringProperty nrKonta;
    private SimpleStringProperty haslo;
    private double stanKonta = 0;
    private boolean  pierwszeWejscie = true;
    private boolean autoryzacja = false;

    Konto(String imie, String nazwisko, String nrKonta,String haslo){

        this.imie = new SimpleStringProperty(imie);
        this.nazwisko= new SimpleStringProperty(nazwisko);
        this.nrKonta= new SimpleStringProperty(nrKonta);
        this.haslo= new SimpleStringProperty(haslo);
    }

    public void setImie(String value) { imie.set(value); }
    public String getImie() { return imie.get(); }

    public void setNazwisko(String value) { nazwisko.set(value); }
    public String getNazwisko() { return nazwisko.get(); }

    public void setNrKonta(String value) { nrKonta.set(value); }
    public String getNrKonta() { return nrKonta.get(); }

    public void setHaslo(String value) { haslo.set(value); }
    public String getHaslo() { return haslo.get(); }

    public boolean zaloguj(String podanyLogin, String podaneHaslo){

        if(podaneHaslo.equals(haslo) && podanyLogin.equals(nrKonta)){
            autoryzacja = true;
        }
        return autoryzacja;
    }
}
package kontobankowe;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

public class Bank {

    public ObservableList<Konto>  getKonta(){

        ObservableList<Konto> klienci = FXCollections.observableArrayList();
        klienci.add(new Konto("Jan","Kowalski","0002","1234"));
        klienci.add(new Konto("Adam","Nowak","0003","1234"));
        klienci.add(new Konto("Piotr","Kwiatkowski","0004","1234"));

        return klienci;
    }
}
package kontobankowe;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;

public class KontoBankowe extends Application implements Initializable{

    //Logowanie admin
    @FXML private Label statusAdmin;

    @FXML private TextField txtAdminLogin;

    @FXML private TextField txtAdminHasloLogowania;

    @FXML private Button btnAdminZaloguj;

     // admin controller
    @FXML private TableView<Konto> tableView;

    @FXML private TableColumn<Konto, String> kolumnaImie;

    @FXML private TableColumn<Konto, String> kolumnaNazwisko;

    @FXML private TableColumn<Konto, String> kolumnaNumerKonta;

    @FXML private TableColumn<Konto, String> kolumnaHaslo;

    @FXML private Label zalogowanyAdmin;

    @FXML private TextField txtImie;

    @FXML private TextField txtNazwisko;

    @FXML private TextField txtNrKonta;

    @FXML private TextField txtPierwszeHaslo;

    @FXML private Button btnDodaj;

    @FXML private Button btnUsun;

    @FXML private Button btnZatwierdz;

    @FXML private Button btnWylogujAdmina;

    Bank bank = new Bank();
    Administrator admin = new Administrator("Jan","Nowak","0001","1234");

    //Logowanie klient
    @FXML private Label statusKlient;

    @FXML private TextField txtKlientLogin;

    @FXML private TextField txtKlientHasloLogowania;

    @FXML private Button btnKlientZaloguj;

    // klient controller

    @FXML private Button btnWylogujKlienta;

    Konto konto = new Konto("Krzysztof", "Kowalski", "0001", "1234");

    public void zalogujAdministratora(ActionEvent event){
        if(admin.zaloguj(bank, txtAdminLogin.getText(), txtAdminHasloLogowania.getText())){
            try {
                Parent adminWidok = FXMLLoader.load(getClass().getResource("FXMLAdministrator.fxml"));
                Scene scene = new Scene(adminWidok);
                Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();

                window.setScene(scene);
                window.show();

                //zalogowanyAdmin.setText("Zalogowany: " + " "+ admin.getImie() +" "+ admin.getNazwisko());

            } catch (IOException e) {
                e.getCause().printStackTrace();
            }

        }
        else{
            statusAdmin.setText("Logowanie Administratora nie powiodło się");
        }
    }

    public void zalogujKlienta(ActionEvent event){
        if(konto.zaloguj(txtKlientLogin.getText(), txtKlientHasloLogowania.getText())){
            try {
                Parent adminWidok = FXMLLoader.load(getClass().getResource("FXMLKlient.fxml"));
                Scene scene = new Scene(adminWidok);
                Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();

                window.setScene(scene);
                window.show();

            } catch (IOException e) {
                e.getCause().printStackTrace();
            }
        }
        else{
            statusKlient.setText("Logowanie Klienta nie powiodło się");
        }
    }

    public void wyloguj(ActionEvent event) {

        try {
            Parent menuWidok = FXMLLoader.load(getClass().getResource("FXMLMenu.fxml"));
            Scene scene = new Scene(menuWidok);
            Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();

            window.setScene(scene);
            window.show();

        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        //set up the columns in the table
        kolumnaImie.setCellValueFactory(new PropertyValueFactory<Konto, String>("imie"));
        kolumnaNazwisko.setCellValueFactory(new PropertyValueFactory<Konto, String>("nazwisko"));
        kolumnaNumerKonta.setCellValueFactory(new PropertyValueFactory<Konto, String>("nrKonta"));
        kolumnaHaslo.setCellValueFactory(new PropertyValueFactory<Konto, String>("haslo"));

        //load data
        tableView.setItems(bank.getKonta());

    }

    @Override
    public void start(Stage stage){
        try {
            Parent root = FXMLLoader.load(getClass().getResource("FXMLMenu.fxml"));
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        launch(args);
    }
}

kod błędu:

Executing C:\Users\fejkl\Desktop\KontoBankowe\dist\run1265183293\KontoBankowe.jar using platform D:\Apps\Java\JDK\jre/bin/java
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java:8411)
    at javafx.scene.control.Button.fire(Button.java:185)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
Caused by: 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 sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
    ... 48 more
Caused by: javafx.fxml.LoadException: 
file:/C:/Users/fejkl/Desktop/KontoBankowe/dist/run1265183293/KontoBankowe.jar!/kontobankowe/FXMLLogowanieAdministrator.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 kontobankowe.MenuController.pokazLogowanieAdministratora(MenuController.java:30)
    ... 58 more
Caused by: java.lang.NullPointerException
    at kontobankowe.KontoBankowe.initialize(KontoBankowe.java:140)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    ... 66 more

Pozostało 580 znaków

2019-01-06 23:15
0

a pokaż fxml

Pozostało 580 znaków

2019-01-06 23:22
Wielki Szewc
0

Wszystkie pliki FXML czy interesuje Cię konkretny? Scene Builder tworzy trochę nadmiarowego kodu więc nie chcę zaśmiecać.

FXMLLogowanieAdministrator.fxml - Berylo 2019-01-07 10:27

Pozostało 580 znaków

2019-01-07 12:27
Wielki Szewc
0

FXMLLogowanieAdministrator


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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<VBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kontobankowe.KontoBankowe">
   <children>
      <Label fx:id="statusAdmin" alignment="CENTER" contentDisplay="TOP" text="Logowanie Administratora" textAlignment="CENTER">
         <font>
            <Font name="System Bold" size="25.0" />
         </font>
         <VBox.margin>
            <Insets bottom="50.0" />
         </VBox.margin>
      </Label>
      <GridPane alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="119.0" prefWidth="448.0">
        <columnConstraints>
          <ColumnConstraints hgrow="SOMETIMES" maxWidth="238.0" minWidth="10.0" prefWidth="152.0" />
          <ColumnConstraints fillWidth="false" hgrow="SOMETIMES" maxWidth="308.0" minWidth="10.0" prefWidth="296.0" />
        </columnConstraints>
        <rowConstraints>
          <RowConstraints maxHeight="108.0" minHeight="10.0" prefHeight="55.0" vgrow="SOMETIMES" />
          <RowConstraints maxHeight="89.0" minHeight="0.0" prefHeight="50.0" vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <TextField fx:id="txtAdminLogin" prefHeight="39.0" prefWidth="240.0" GridPane.columnIndex="1">
               <font>
                  <Font size="18.0" />
               </font>
            </TextField>
            <PasswordField fx:id="txtAdminHasloLogowania" prefHeight="39.0" prefWidth="240.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
               <GridPane.margin>
                  <Insets top="20.0" />
               </GridPane.margin>
               <font>
                  <Font size="18.0" />
               </font>
            </PasswordField>
            <Label alignment="CENTER" contentDisplay="CENTER" text="Login:" GridPane.halignment="RIGHT">
               <font>
                  <Font size="24.0" />
               </font>
               <GridPane.margin>
                  <Insets right="20.0" />
               </GridPane.margin>
            </Label>
            <Label text="Hasło:" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
               <font>
                  <Font size="24.0" />
               </font>
               <GridPane.margin>
                  <Insets right="20.0" top="20.0" />
               </GridPane.margin>
            </Label>
         </children>
      </GridPane>
      <Button fx:id="btnAdminZaloguj" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#zalogujAdministratora" prefHeight="37.0" prefWidth="116.0" text="Zaloguj">
         <VBox.margin>
            <Insets top="50.0" />
         </VBox.margin></Button>
   </children>
</VBox>

Chciałbym tylko wyświetlić kolekcje w TableView ObservableList z klasy Bank w widoku FXMLAdministrator
Jak na filmie:

https://www.youtube.com/watch[...]YCdd5MYS4CKVbGHv2&index=7

FXMLAdministrator


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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kontobankowe.KontoBankowe">
  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" maxWidth="835.0" minWidth="10.0" prefWidth="835.0" />
    <ColumnConstraints hgrow="SOMETIMES" maxWidth="595.0" minWidth="10.0" prefWidth="365.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints maxHeight="519.0" minHeight="10.0" prefHeight="519.0" vgrow="SOMETIMES" />
    <RowConstraints maxHeight="341.0" minHeight="10.0" prefHeight="281.0" vgrow="SOMETIMES" />
    <RowConstraints maxHeight="137.0" minHeight="0.0" prefHeight="0.0" vgrow="SOMETIMES" />
  </rowConstraints>
   <children>
      <GridPane GridPane.rowIndex="1">
        <columnConstraints>
          <ColumnConstraints hgrow="SOMETIMES" maxWidth="412.0" minWidth="10.0" prefWidth="242.0" />
          <ColumnConstraints hgrow="SOMETIMES" maxWidth="597.0" minWidth="10.0" prefWidth="593.0" />
        </columnConstraints>
        <rowConstraints>
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <Label text="Imię:" GridPane.halignment="RIGHT">
               <font>
                  <Font size="24.0" />
               </font>
               <GridPane.margin>
                  <Insets right="20.0" />
               </GridPane.margin>
            </Label>
            <Label layoutX="10.0" layoutY="26.0" text="Nazwisko:" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
               <font>
                  <Font size="24.0" />
               </font>
               <GridPane.margin>
                  <Insets right="20.0" />
               </GridPane.margin>
            </Label>
            <Label layoutX="10.0" layoutY="77.0" text="Numer konta:" GridPane.halignment="RIGHT" GridPane.rowIndex="2">
               <font>
                  <Font size="24.0" />
               </font>
               <GridPane.margin>
                  <Insets right="20.0" />
               </GridPane.margin>
            </Label>
            <Label layoutX="10.0" layoutY="128.0" text="Hasło:" GridPane.halignment="RIGHT" GridPane.rowIndex="3">
               <font>
                  <Font size="24.0" />
               </font>
               <GridPane.margin>
                  <Insets right="20.0" />
               </GridPane.margin>
            </Label>
            <PasswordField fx:id="txtPierwszeHaslo" GridPane.columnIndex="1" GridPane.rowIndex="3">
               <font>
                  <Font size="20.0" />
               </font>
            </PasswordField>
            <TextField fx:id="txtNrKonta" GridPane.columnIndex="1" GridPane.rowIndex="2">
               <font>
                  <Font size="20.0" />
               </font>
            </TextField>
            <TextField fx:id="txtNazwisko" layoutX="252.0" layoutY="155.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
               <font>
                  <Font size="20.0" />
               </font>
            </TextField>
            <TextField fx:id="txtImie" layoutX="252.0" layoutY="91.0" GridPane.columnIndex="1">
               <font>
                  <Font size="20.0" />
               </font>
            </TextField>
         </children>
      </GridPane>
      <VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" GridPane.columnIndex="1">
         <children>
            <Label fx:id="zalogowanyAdmin" alignment="CENTER" contentDisplay="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="30.0" minWidth="-Infinity" prefWidth="330.0" text="Zalogowany: " textAlignment="CENTER">
               <font>
                  <Font size="18.0" />
               </font>
               <VBox.margin>
                  <Insets bottom="100.0" left="10.0" right="10.0" />
               </VBox.margin>
            </Label>
            <Button fx:id="btnDodaj" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefWidth="150.0" text="Dodaj" textAlignment="CENTER">
               <font>
                  <Font size="18.0" />
               </font>
               <VBox.margin>
                  <Insets bottom="25.0" />
               </VBox.margin>
            </Button>
            <Button fx:id="btnUsun" mnemonicParsing="false" prefWidth="150.0" text="Usuń" textAlignment="CENTER">
               <font>
                  <Font size="18.0" />
               </font>
               <VBox.margin>
                  <Insets bottom="25.0" />
               </VBox.margin>
            </Button>
            <Button fx:id="btnZatwierdz" mnemonicParsing="false" prefWidth="150.0" text="Zatwierdź" textAlignment="CENTER">
               <font>
                  <Font size="18.0" />
               </font>
               <VBox.margin>
                  <Insets bottom="25.0" />
               </VBox.margin>
            </Button>
            <Button fx:id="btnWylogujAdmina" mnemonicParsing="false" onAction="#wyloguj" prefWidth="150.0" text="Wyloguj" textAlignment="CENTER">
               <font>
                  <Font size="18.0" />
               </font>
            </Button>
         </children>
      </VBox>
      <TableView fx:id="tableView" prefHeight="200.0" prefWidth="200.0">
        <columns>
          <TableColumn fx:id="kolumnaImie" prefWidth="142.0" text="Imię" />
          <TableColumn fx:id="kolumnaNazwisko" prefWidth="133.0" text="Nazwisko" />
            <TableColumn fx:id="kolumnaNumerKonta" prefWidth="164.0" text="Numer Konta" />
            <TableColumn fx:id="kolumnaHaslo" minWidth="4.0" prefWidth="155.0" text="Haslo" />
        </columns>
      </TableView>
   </children>
</GridPane>

Pozostało 580 znaków

2019-01-07 16:12
0

Jak definiujesz to w ten sposób to powinieneś mieć odpowiednie gettery. Więcej tutaj: https://stackoverflow.com/que[...]efactory-advantages-disadvant

Możesz też użyć lambdy i zamiast tak:

kolumnaImie.setCellValueFactory(new PropertyValueFactory<Konto, String>("imie"));

zrób tak:

kolumnaImie.setCellValueFactory(cellData -> cellData.getValue().getImieProperty());

W klasie Konto powinieneś mieć zdefionowane imieProperty (możesz wrzucić klasę Konto tutaj)

Pozostało 580 znaków

2019-01-07 16:21
Wielki Szewc
0

Zmieniłem trochę w kodzie. Rozdzieliłem ten bałagan z klasy KontoBankowe na AdministratorController i KlientController. Odpaliłem TableView bez logowania i lista została dodana jednak nadal jest problem z metodą initialize() w AdministratorController. Jestem w trakcje jej rozwiązywania za pomocą :
https://stackoverflow.com/questions/40902407/initialize-method-javafx-nullpointer

Jeśli nie przyniesie skutek to wrzucę wszystko od nowa po zastosowaniu Twoich wskazówek.

Pozostało 580 znaków

2019-01-07 16:57
Wielki Szewc
0

Dodałem właściwości lecz nie wiem czy są one prawidłowo napisanie.

Konto:

package kontobankowe;

import javafx.beans.property.SimpleStringProperty;

public class Konto {

    private SimpleStringProperty imie;
    private SimpleStringProperty nazwisko;
    private SimpleStringProperty nrKonta;
    private SimpleStringProperty haslo;
    private boolean autoryzacja = false;

    Konto(String imie, String nazwisko, String nrKonta,String haslo){

        this.imie = new SimpleStringProperty(imie);
        this.nazwisko= new SimpleStringProperty(nazwisko);
        this.nrKonta= new SimpleStringProperty(nrKonta);
        this.haslo= new SimpleStringProperty(haslo);
    }

    public void setImie(String value) { imie.set(value); }
    public String getImie() { return imie.get(); }
    public SimpleStringProperty imieProperty() { 
         if (imie == null) imie = new SimpleStringProperty(this, "imie");
         return imie; 
    }

    public void setNazwisko(String value) { nazwisko.set(value); }
    public String getNazwisko() { return nazwisko.get(); }
    public SimpleStringProperty nazwiskoProperty() { 
         if (nazwisko == null) nazwisko = new SimpleStringProperty(this, "nazwisko");
         return nazwisko; 
    }

    public void setNrKonta(String value) { nrKonta.set(value); }
    public String getNrKonta() { return nrKonta.get(); }
    public SimpleStringProperty nrKontaProperty() { 
         if (nrKonta == null) nrKonta = new SimpleStringProperty(this, "nrKonta");
         return nrKonta; 
    }

    public void setHaslo(String value) { haslo.set(value); }
    public String getHaslo() { return haslo.get(); }
    public SimpleStringProperty hasloProperty() { 
         if (haslo == null) haslo = new SimpleStringProperty(this, "haslo");
         return haslo; 
    }

    public boolean zaloguj(String podanyLogin, String podaneHaslo){

        if(podaneHaslo.equals(haslo.get()) && podanyLogin.equals(nrKonta.get())){
            autoryzacja = true;
        }
        return autoryzacja;
    }
}

Jednak nadal występuje w tej metodzie NullPointerException
AdministratorController po zmianie:

@Override
    public void initialize(URL url, ResourceBundle rb) {
        //set up the columns in the table
        kolumnaImie.setCellValueFactory(cellData -> cellData.getValue().imieProperty());
        kolumnaNazwisko.setCellValueFactory(cellData -> cellData.getValue().nazwiskoProperty());
        kolumnaNumerKonta.setCellValueFactory(cellData -> cellData.getValue().nrKontaProperty());
        kolumnaHaslo.setCellValueFactory(cellData -> cellData.getValue().hasloProperty());

        //load data
        tableView.setItems(bank.getKonta());

    }

kod błędu:

Executing C:\Users\fejkl\Desktop\KontoBankowe\dist\run2128667303\KontoBankowe.jar using platform D:\Apps\Java\JDK\jre/bin/java
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java:8411)
    at javafx.scene.control.Button.fire(Button.java:185)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
Caused by: 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 sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
    ... 48 more
Caused by: javafx.fxml.LoadException: 
file:/C:/Users/fejkl/Desktop/KontoBankowe/dist/run2128667303/KontoBankowe.jar!/kontobankowe/FXMLLogowanieAdministrator.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 kontobankowe.MenuController.pokazLogowanieAdministratora(MenuController.java:30)
    ... 58 more
Caused by: java.lang.NullPointerException
    at kontobankowe.AdministratorController.initialize(AdministratorController.java:91)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    ... 66 more

Pozostało 580 znaków

2019-01-07 18:10
0

A na jakiej dokładnie linii leci ci ten nullpointer?

Pozostało 580 znaków

Odpowiedz
Liczba odpowiedzi na stronę

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0