j'ai fais quelques changements mais je reçois null exception
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
@FXML
private TableView<systeme> sysTable;
@FXML
private TableColumn<systeme, String> idCol;
@FXML
private TableColumn<systeme, String> sysCol;
//remplissage du tableau
public void initTable() throws Exception {
mySys = sqlObj.getAllSys();// appel de la méthode qui extrait de la bdd
idCol.setCellValueFactory(new PropertyValueFactory<>("id"));
sysCol.setCellValueFactory(new PropertyValueFactory<>("sys"));
sysTable.setItems(null);
sysTable.getColumns().addAll(idCol, sysCol);
sysTable.setItems(mySys);
} |
la méthode getAllSys()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
//Selectionner tous les systèmes pour le tableau
public ObservableList getAllSys() throws SQLException {
cnx = Conn.Connect();
String query = "SELECT * FROM systeme";
try {
ps = cnx.prepareStatement(query);
rs = ps.executeQuery();
while (rs.next()) {
mySys.add(new systeme(rs.getString(1), rs.getString(2)));
}
return mySys;
} catch (Exception e) {
System.err.println("Error" + e);
return null;
} finally {
if (ps != null) {
ps.close();
}
if (cnx != null) {
cnx.close();
}
}
} |
voici l'exception
Errorjava.lang.NullPointerException
java.lang.NullPointerException
at amdec.system.SystemeController.initTable(SystemeController.java:58)
at amdec.AMDECController.loadSysteme(AMDECController.java:53)
la ligne indiqué est celle où j'instancié les colonnes
idCol.setCellValueFactory(new PropertyValueFactory<>("id"));
Partager