Witam mam problem z wyświetleniem tabeli w JavieFX
polowe wyświetla, a na połowie kolumn wyrzuca błędy:
WARNING: Can not retrieve property 'numer_grupy' in PropertyValueFactory: javafx.scene.control.cell.PropertyValueFactory@1e9f6477 with provided class type: class pl.dziennik.ModelStudentList
java.lang.IllegalStateException: Cannot read from unreadable property numer_grupy
WARNING: Can not retrieve property 'rok_studiow' in PropertyValueFactory: javafx.scene.control.cell.PropertyValueFactory@4d06501f with provided class type: class pl.dziennik.ModelStudentList
java.lang.IllegalStateException: Cannot read from unreadable property rok_studiow
Controller:
package pl.dziennik;
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 java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ResourceBundle;
public class ControllerStudentList implements Initializable {
Connection c = null;
Statement stmt = null;
@FXML
private TableView<ModelStudentList> tabelaListyStudentow;
@FXML
private TableColumn<ModelStudentList, Integer> kolumnaId;
@FXML
private TableColumn<ModelStudentList, String> kolumnaImie;
@FXML
private TableColumn<ModelStudentList, String> kolumnaNazwisko;
@FXML
private TableColumn<ModelStudentList, Integer> kolumnaNrGrupy;
@FXML
private TableColumn<ModelStudentList, Integer> kolumnaRokStudiow;
ObservableList<ModelStudentList> listaDoTabeli = FXCollections.observableArrayList();
@Override
public void initialize(URL location, ResourceBundle resources) {
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:C:\\xampp\\htdocs\\java-projek\\bazaDziekanat");
System.out.println("Polaczenie z baza: poprawne");
} catch (Exception e) {
System.out.println("Polaczenie z baza: niepoprawne: " + e.getMessage());
}
try {
this.stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Student");
while(rs.next()) {
listaDoTabeli.add(new ModelStudentList(rs.getInt("id"),
rs.getString("imie"), rs.getString("nazwisko"),
rs.getInt("numer_grupy"), rs.getInt("rok_studiow")));
}
} catch (Exception e) {
System.out.println("Blad: " + e.getMessage());
}
kolumnaId.setCellValueFactory(new PropertyValueFactory<>("id"));
kolumnaImie.setCellValueFactory(new PropertyValueFactory<>("imie"));
kolumnaNazwisko.setCellValueFactory(new PropertyValueFactory<>("nazwisko"));
kolumnaNrGrupy.setCellValueFactory(new PropertyValueFactory<>("numer_grupy"));
kolumnaRokStudiow.setCellValueFactory(new PropertyValueFactory<>("rok_studiow"));
tabelaListyStudentow.setItems(listaDoTabeli);
}
}
Model
package pl.dziennik;
public class ModelStudentList {
private int id, numer_grupy, rok_studiow;
private String imie, nazwisko;
public ModelStudentList(int id, String imie, String nazwisko, int numer_grupy, int rok_studiow) {
this.id = id;
this.imie= imie;
this.nazwisko = nazwisko;
this.numer_grupy = numer_grupy;
this.rok_studiow = rok_studiow;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getImie() {
return imie;
}
public void setImie(String imie) {
this.imie = imie;
}
public String getNazwisko() {
return nazwisko;
}
public void setNazwisko(String nazwisko) {
this.nazwisko = nazwisko;
}
public int getNumerGrupy() {
return numer_grupy;
}
public void setNumerGrup(int numer_grupy) {
this.numer_grupy = numer_grupy;
}
public int getRokStudiow() {
return rok_studiow;
}
public void setRokStudiow(int rok_studiow) {
this.rok_studiow = rok_studiow;
}
}
FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="400.0" minWidth="641.0" prefHeight="400.0" prefWidth="641.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="pl.dziennik.ControllerStudentList">
<children>
<TableView fx:id="tabelaListyStudentow" layoutX="147.0" layoutY="68.0" prefHeight="400.0" prefWidth="700.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="kolumnaId" prefWidth="29.00000035762787" text="ID" />
<TableColumn fx:id="kolumnaImie" prefWidth="162.99999046325684" text="Imie" />
<TableColumn fx:id="kolumnaNazwisko" prefWidth="160.0" text="Nazwisko" />
<TableColumn fx:id="kolumnaNrGrupy" prefWidth="117.79998779296875" text="Nr grupy" />
<TableColumn fx:id="kolumnaRokStudiow" prefWidth="119.79995727539062" text="Rok studiow" />
</columns>
</TableView>
</children>
</AnchorPane>