Java.lang.NullPointerException
killyox
-
KX Messages postés 16761 Date d'inscription Statut Modérateur Dernière intervention -
KX Messages postés 16761 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour, j'ai un problème dans mon code. Je débute en programmation et je suis entrein de programmer un programme qui permet de faire la gestion de dossier. Les dossiers sont stocké dans une ArrayList et ils sont définie via une interface graphique.
Le problème est que quand je veux rechercher/supprimer un dossier il me sort tout plein d'erreur, que voici:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at FenetrePrincipale.actionPerformed(FenetrePrincipale.java:129)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
L'erreur vient de cette partie de mon code ( la deuxième ligne):
La fonction recherche est la suivante:
Pouvez vous me dire d'ou vient mon erreur ? Merci d'avance
Le problème est que quand je veux rechercher/supprimer un dossier il me sort tout plein d'erreur, que voici:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at FenetrePrincipale.actionPerformed(FenetrePrincipale.java:129)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
L'erreur vient de cette partie de mon code ( la deuxième ligne):
doss=carton.recherche(numero,nom,ref); saisiNumero.setText(doss.getNumeroDossier());
La fonction recherche est la suivante:
public Dossier recherche(String numero, String nom, String ref){ Dossier doss ,doss1=null; boolean trouve =false ; Iterator<Dossier> it = ensembleDossier.iterator(); while(it.hasNext()){ if(!trouve){ doss = it.next(); if(numero==doss.getNumeroDossier() || nom == doss.getNomAssure() || ref==doss.getRefIntervenant()){ doss1 =doss; trouve = true; } }else{doss1=null;} } if(!trouve){JOptionPane.showMessageDialog(null,"Aucun dossier n'a été trouvé sous ces références");} return doss1; }
Pouvez vous me dire d'ou vient mon erreur ? Merci d'avance
3 réponses
NullPointerException signifie qu'un des objets que tu utilises vaut null alors qu'il doit être initialisé.
Vu le message d'erreur, le problème est dans ta méthode actionPerformed (ligne 129), pas dans la méthode recherche que tu nous donne.
Donc si le code "saisiNumero.setText(doss.getNumeroDossier());" est bien cette ligne 129 dans actionPerformed, alors tu as soit saisiNumero==null, soit doss==null
Dans les deux cas, il faut donner une valeur à la variable concerné avant de faire un appel de méthode.
Vu le message d'erreur, le problème est dans ta méthode actionPerformed (ligne 129), pas dans la méthode recherche que tu nous donne.
Donc si le code "saisiNumero.setText(doss.getNumeroDossier());" est bien cette ligne 129 dans actionPerformed, alors tu as soit saisiNumero==null, soit doss==null
Dans les deux cas, il faut donner une valeur à la variable concerné avant de faire un appel de méthode.
Merci de ta réponce. Je vois mieux d'où vient mon erreur. Dans ma méthode recherche j'initialise doss = null.
L'erreur doit surrment être produite à partir d'ici.
L'erreur doit surrment être produite à partir d'ici.