Bonjour à tous. Je suis un peu débutant en java et je développe une petite application pour un devoir à l'école. J'ai hésité à poser ma question ici ou dans la forum dédié a JDBC donc finalement je l'ai posté dans les deux ...
Bon la technologie utilisé est JAVAFX et j’ai une vue avec des labels nom, prénom, tel... que je charge automatiquement comme enfants de mon conteneur dans un tableau en faisant la requête de sélection dans ma base de données ce qui me charge bien ma vue une seule fois car je n'est qu'un seul enregistrement. Mais maintenant au moment de remplacer le texte des labels chaque fois que ma vue est chargée ça me retourne plutôt un java.sql.sqlexcemption : after end of resultset.J'ai éssayer de résourdre le problème en mettant le chargement de ma vue dans un évènement mais maintenant j'ain un java.lang.nullpointerexception
Bref je vous laisse regarder et merci d'avance.
Voici le controlleur de la page d'acceuil
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 
public void initialize(URL location, ResourceBundle resources) {
		acceuilButton.setOnAction(event -> {
		Reservation reservation = new Reservation();
		try {
			ResultSet rs = reservation.getAllReservation();
			//rs.last();
			//rs.beforeFirst();
			int i = 0;
			ResultSetMetaData resultmetadata = rs.getMetaData();
			Node [] nodes = new Node[resultmetadata.getColumnCount()];
			rs.beforeFirst();
			while(rs.next()) {
				try {
					nodes[i] = (Node)FXMLLoader.load(getClass().getResource("/views/ListItemView.fxml"));
					//give the items some effect
					final int j = i;
	                /*nodes[i].setOnMouseEntered(event -> {
	                    nodes[j].setStyle("-fx-background-color : #0A0E3F");
	                });
	                nodes[i].setOnMouseExited(event -> {
	                    nodes[j].setStyle("-fx-background-color : #02030A");
	                });*/
					Conteneur.getChildren().add(nodes[i]);
					/*System.out.println(rs.getString("nom"));
					System.out.println(rs.getString("prenom"));
					System.out.println(rs.getString("tel"));
					System.out.println(rs.getInt("numchambre"));
					System.out.println(rs.getInt("prix"));
					System.out.println(rs.getString("description"));
					System.out.println(rs.getDate("datedebut"));
					System.out.println(rs.getDate("datefin"));*/
					//acceuilButton.setOnAction(event -> {
						try {
							ListItemController.setInformations(rs.getString("nom"), rs.getString("prenom"), rs.getString("tel"), rs.getInt("numchambre"), rs.getInt("prix"), rs.getString("description"), rs.getDate("datedebut"), rs.getDate("datefin"));
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					//});
 
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		});
 
		/*for(int i=0;i < nodes.length;i++) {
			try {
				nodes[i] = (Node)FXMLLoader.load(getClass().getResource("/views/ListItemView.fxml"));
				//give the items some effect
				final int j = i;
                nodes[i].setOnMouseEntered(event -> {
                    nodes[j].setStyle("-fx-background-color : #0A0E3F");
                });
                nodes[i].setOnMouseExited(event -> {
                    nodes[j].setStyle("-fx-background-color : #02030A");
                });
				Conteneur.getChildren().add(nodes[i]);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}*/
 
	}
Le controlleur de ma vue en question
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
59
60
61
 
package controllers;
 
import java.net.URL;
import java.sql.Date;
import java.time.LocalDate;
import java.util.ResourceBundle;
 
import com.jfoenix.controls.JFXButton;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
 
public class ListItemController implements Initializable{
	 @FXML
	    private static Label nomClient;
 
	    @FXML
	    private static Label prenomClient;
 
	    @FXML
	    private static Label telClient;
 
	    @FXML
	    private static Label numChambreClient;
 
	    @FXML
	    private static Label prixChambreClient;
 
	    @FXML
	    private static Label categorieChambreClient;
 
	    @FXML
	    private static Label dateDebutSejourClient;
 
	    @FXML
	    private static Label dateFinSejourClient;
 
	    @FXML
	    private static JFXButton updateReservation;
 
	    @FXML
	    private static JFXButton deleteReservation;
 
		@Override
		public void initialize(URL location, ResourceBundle resources) {
			// TODO Auto-generated method stub
 
		}
 
		public static void setInformations(String nom,String prenom,String tel,int numchambre,int prix, String categorie,Date datedebut, Date datefin) {
			nomClient.setText(nom);
			prenomClient.setText(prenom);
			telClient.setText(tel);
			numChambreClient.setText(Integer.toString(numchambre));
			prixChambreClient.setText(Integer.toString(prix));
			categorieChambreClient.setText(categorie);
			dateDebutSejourClient.setText(datedebut.toString());
			dateFinSejourClient.setText(datefin.toString());
		}
}
Le code de mon model Reservation
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
package models;
 
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
 
import application.DBConnection;
import application.Parameter;
 
public class Reservation {
	DBConnection connection = new DBConnection(Parameter.HOST_DB, Parameter.USERNAME_DB, Parameter.PASSWORD_DB,
			Parameter.IPHOST, Parameter.PORT);
	private String codeClient;
	private int numChambre;
	private Date dateDebut;
	private Date dateFin;
 
	public Reservation(String codeClient, int numChambre, Date dateDebut, Date dateFin) {
		this.codeClient = codeClient;
		this.numChambre = numChambre;
		this.dateDebut = dateDebut;
		this.dateFin = dateFin;
	}
 
	public Reservation() {
 
	}
 
	public ResultSet getAllReservation() {
		try {
			Connection connect = connection.connexionDatabase();
			String sql = "SELECT nom,prenom,client.tel,chambre.numchambre,prix,chambre.tel,prix,description,datedebut,datefin FROM reservation,client,chambre,categorie WHERE client.codeclient=reservation.codeclient  AND chambre.numchambre=reservation.numchambre AND categorie.id=chambre.idcategorie";
			PreparedStatement ps = connect.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			return rs;
		} catch (Exception e) {
			System.out.print(e.getMessage());
		}
		return null;
	}
}
code de l'erreur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
	at controllers.ListItemController.setInformations(ListItemController.java:51)
	at controllers.AcceuilFormController.lambda$0(AcceuilFormController.java:117)
	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.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.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(Unknown Source)
Voici un peu comment cela se présente en interface
Nom : Capturei.PNG
Affichages : 943
Taille : 181,6 Ko
En rouge ce sont les labels de ma vue en question à modifier