j’appelle une fenêtre contenant un treeView via un bouton en passant un paramètre
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| @FXML
private Button btnGraph;
String id;//paramètre à passer
//méthode d'appel de la fenêtre en passant le paramètre
public void afficheGraph() throws Exception {
Stage graphStage = new Stage();
FXMLLoader loader = new FXMLLoader();
Pane rootGraph = loader.load(getClass().getResource("graph/graph.fxml").openStream());
GraphController controller = (GraphController)loader.getController();
controller.getSystemChoice(id);
Scene sceneGraph = new Scene(rootGraph);
sceneGraph.getStylesheets().add(getClass().getResource("myStyle.css").toExternalForm());
graphStage.setTitle("Graphe");
graphStage.setScene(sceneGraph);
graphStage.show();
} |
le contrôleur de la fenêtre du graphe est le suivant
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
//méthode qui reçoit le paramètre
public void getSystemChoice(String sys){ id = obj.getIdSys(sys);
}
//méthode qui remplis le treeView
private void fillTree(String idSys) {
String query = "SELECT * FROM composant WHERE id=?";
try {
ps = cnx.prepareStatement(query);
ps.setString(1, idSys);
rs = ps.executeQuery();
while (rs.next()) {
int code = rs.getInt("code");
String composant = rs.getString("composant");
int parent = rs.getInt("parent");
String niveau = rs.getString("niveau");
int id = rs.getInt("id");
c = new composant(code, composant, niveau, parent, id);
node.put(code, c);
pere.put(parent, c);
}
ps.close();
rs.close();
} catch (Exception e) {
System.err.println("Error" + e);
}
TreeItem<String> system = new TreeItem<>(sys);
//parcours des peres
for (Integer k : pere.keySet()) {
composant p = pere.get(k);
TreeItem<String> parent = new TreeItem<>();
parent.setValue(p.getComposant());
//parcours des fils
for (Integer i : node.keySet()) {
composant c = node.get(i);
TreeItem<String> noeud = new TreeItem<>();
noeud.setValue(c.getComposant());
if (c.getParent() == k) {
parent.getChildren().add(noeud);
}
}
}
tree.setRoot(system);
}
//méthode d'initialisation qui appelle ma méthode de remplissage
@Override
public void initialize(URL url, ResourceBundle rb) {
fillTree(id);
} |
en compilant je reçois cette erreur
Caused by: java.lang.NullPointerException
et il pointe ce code
Pane rootGraph = loader.load(getClass().getResource("graph/graph.fxml").openStream());
quelle est le problème avec mon code je vous prie ??
merci
Partager