Précédent   Forum du club des développeurs et IT Pro > Java > Général Java
Général Java Java SE, Java ME, APIs, Persistance, JDBC, Spring, XML. Avant de poster -> FAQ Java, Sources Java
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 17/11/2012, 12h40   #1
mehdi.cheddani
 
Homme mehdi cheddani
génie logiciel
Inscription : mars 2012
Messages : 84
Détails du profil
Informations personnelles :
Nom : Homme mehdi cheddani
Localisation : Maroc

Informations professionnelles :
Activité : génie logiciel

Informations forums :
Inscription : mars 2012
Messages : 84
Points : -5
Points : -5
Par défaut Correction d'une NullPointerException

Bonjour,

Je voudrai avoir votre aide. Mon code est le suivant:
Code :
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
jComboBox.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					try {
						Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
						Connection cn=DriverManager.getConnection("jdbc:odbc:Bd"); 
						Statement st=cn.createStatement();
						String o=jComboBox.getSelectedItem().toString(); 
						ResultSet rs=st.executeQuery("select sous_quartier,cil,quartier,nom,avis_acces,porte,rue from Rabat where N_Ordre_Redal='"+o+"';"); 
						while (rs.next()) { 
						jTextField.setText(rs.getObject("sous_quartier").toString());//voici la ligne 83
						jTextField1.setText(rs.getObject("cil").toString());
						jTextField2.setText(rs.getObject("quartier").toString());
						jTextField3.setText(rs.getObject("nom").toString());
						jTextField4.setText(rs.getObject("avis_acces").toString());
						jTextField5.setText(rs.getObject("porte").toString());
						jTextField6.setText(rs.getObject("rue").toString());
						} 
					} catch (ClassNotFoundException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} 
 
				}
			});
Quand je compile et j'exécute j'ai un message d'erreur que voila:
Citation:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at metier.Saisie$1.itemStateChanged(Saisie.java:83)
at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1205)
at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1262)
at javax.swing.JComboBox.contentsChanged(JComboBox.java:1309)
at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:100)
at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:88)
at javax.swing.DefaultComboBoxModel.addElement(DefaultComboBoxModel.java:126)
at javax.swing.JComboBox.addItem(JComboBox.java:696)
at metier.Saisie.getJComboBox(Saisie.java:107)
at metier.Saisie.getJContentPane(Saisie.java:500)
at metier.Saisie.initialize(Saisie.java:426)
at metier.Saisie.<init>(Saisie.java:416)
at metier.Saisie$2.run(Saisie.java:404)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
mehdi.cheddani est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/11/2012, 13h00   #2
tchize_
Expert Confirmé Sénior
 
Avatar de tchize_
 
Homme
Responsable de service informatique
Inscription : avril 2007
Messages : 18 286
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 33
Localisation : Belgique

Informations professionnelles :
Activité : Responsable de service informatique
Secteur : Service public

Informations forums :
Inscription : avril 2007
Messages : 18 286
Points : 32 761
Points : 32 761
Envoyer un message via MSN à tchize_ Envoyer un message via Skype™ à tchize_
Et la ligne
at metier.Saisie$1.itemStateChanged(Saisie.java:83)

correspond à quoi dans ton code?
__________________
⥀⥁ Чиз faq java, cours java, javadoc. Pensez à et
Laisse entrer le jour après une nuit sombre. Si tu es toujours là, tu n'es pas faite pour mourir.
tchize_ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/11/2012, 07h51   #3
sealion
Invité de passage
 
Inscription : novembre 2012
Messages : 1
Détails du profil
Informations forums :
Inscription : novembre 2012
Messages : 1
Points : 1
Points : 1
Citation:
Envoyé par tchize_ Voir le message
Et la ligne
at metier.Saisie$1.itemStateChanged(Saisie.java:83)

correspond à quoi dans ton code?
Citation:
Envoyé par mehdi.cheddani Voir le message
jTextField.setText(rs.getObject("sous_quartier").toString());//voici la ligne 83
"sous_quartier" est-il le bon nom de colonne?
L'objet jTextField a-t-il été instancié?
sealion est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/11/2012, 13h31   #4
tchize_
Expert Confirmé Sénior
 
Avatar de tchize_
 
Homme
Responsable de service informatique
Inscription : avril 2007
Messages : 18 286
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 33
Localisation : Belgique

Informations professionnelles :
Activité : Responsable de service informatique
Secteur : Service public

Informations forums :
Inscription : avril 2007
Messages : 18 286
Points : 32 761
Points : 32 761
Envoyer un message via MSN à tchize_ Envoyer un message via Skype™ à tchize_
je rajoute, sous_quartier peut il être null dans la base de donnée?
__________________
⥀⥁ Чиз faq java, cours java, javadoc. Pensez à et
Laisse entrer le jour après une nuit sombre. Si tu es toujours là, tu n'es pas faite pour mourir.
tchize_ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/11/2012, 00h04   #5
mehdi.cheddani
 
Homme mehdi cheddani
génie logiciel
Inscription : mars 2012
Messages : 84
Détails du profil
Informations personnelles :
Nom : Homme mehdi cheddani
Localisation : Maroc

Informations professionnelles :
Activité : génie logiciel

Informations forums :
Inscription : mars 2012
Messages : 84
Points : -5
Points : -5
mon champ sous_quartier est bien rempli dans la base de données et il est bien écrit au niveau du code je galère.et comment puis je savoir est ce que mon jtextfield est bien instancié.
Merci
mehdi.cheddani est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/11/2012, 11h08   #6
tchize_
Expert Confirmé Sénior
 
Avatar de tchize_
 
Homme
Responsable de service informatique
Inscription : avril 2007
Messages : 18 286
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 33
Localisation : Belgique

Informations professionnelles :
Activité : Responsable de service informatique
Secteur : Service public

Informations forums :
Inscription : avril 2007
Messages : 18 286
Points : 32 761
Points : 32 761
Envoyer un message via MSN à tchize_ Envoyer un message via Skype™ à tchize_
ben déjà montre nous où tu instancie ton jtextfield.
__________________
⥀⥁ Чиз faq java, cours java, javadoc. Pensez à et
Laisse entrer le jour après une nuit sombre. Si tu es toujours là, tu n'es pas faite pour mourir.
tchize_ est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 13h23.


 
 
 
 
Partenaires

Hébergement Web