Exception part moment - Thread

Résolu
SpaceHam Messages postés 78 Date d'inscription lundi 27 mars 2006 Statut Membre Dernière intervention 22 octobre 2015 - 8 déc. 2010 à 20:57
 Utilisateur anonyme - 9 déc. 2010 à 22:38
J'ai dans mon code des exception qui aurait rapport avec le repaint qui apparait régulièrement. En fait c'est tout simplement dans un thread qui après un certain temps ne fait qu'aller chercher la liste des usager en ligne et remet à jour ma JList.

Voici simplement ma partie de source ou j'ai pu en sortir mes System.outprintln...

Le problème semble sortir de updateAllUsersConnect();

En gros je voudrais trouver une solution afin que dans mon interface Swing je ne dois pas a chaque fois attendre par exemple une grosse minute avant qu'il réessaie d,aller rafraichir le JList. A chaque fois que L,exception en sort c'est souvent un objet null donc je n'ai plus de liste pleine mais vide.

Quel façon je pourrais faire pour contourner mon problème.

Merci à l'avance!

Thread
----------------------------------------------------
if(thUpdate == null)
{
thUpdate = new Thread()
{
private boolean update = true;
private int nb = 0;

public void run()
{
try
{
while(update)
{
System.out.println("while(update) #"+nb);
sleep(5000);
System.out.println("end sleep(5000) #"+nb);
updateAllUsersConnect();
System.out.println("updateAllUsersConnect #"+nb);
nb++;
}
}
catch (InterruptedException e)
{
System.out.println("Error Thread : "+e.getMessage());
}
}
};
}
----------------------------------------------------
***plc = ma persistance

public void updateAllUsersConnect()
{
setNomToAList(plc.getAllUserConnect(), vjlusers);
bpp.ucp.miseAJourList();
}
private void setNomToAList(Vector source, Vector liste)
{
liste.removeAllElements();
Iterator it = source.iterator();
while(it.hasNext())
{
Utilisateur user = (Utilisateur)it.next();
liste.add(user.getPrenom()+" "+user.getNom());
}
}
----------------------------------------------------
Exception qui me sort :

end sleep(5000) #13
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicListUI.getHeight(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.paintImpl(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)updateAllUsersConnect #13
while(update) #14

at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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)
end sleep(5000) #14
updateAllUsersConnect #14
while(update) #15
end sleep(5000) #15
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.getPreferredSize(Unknown Source)
updateAllUsersConnect #15
while(update) #16
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at javax.swing.ScrollPaneLayout.layoutContainer(Unknown Source)
at java.awt.Container.layout(Unknown Source)
at java.awt.Container.doLayout(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at javax.swing.RepaintManager.validateInvalidComponents(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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)
end sleep(5000) #16

--------------------------------------------------------------

SpaceHamAgent

8 réponses

Utilisateur anonyme
9 déc. 2010 à 19:38
Fais plutôt comme ça :
while(update)
{System.out.println("while(update) #"+nb);
sleep(5000);
System.out.println("end sleep(5000) #"+nb);
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
updateAllUsersConnect();
}
});
System.out.println("updateAllUsersConnect #"+nb);
nb++;
}






TUER : http://tuer.sourceforge.net/tuer.jnlp

yeah! vive java
3
Utilisateur anonyme
9 déc. 2010 à 12:46
Bonjour

Ne manipule ta JList que depuis l'Event Dispatching Thread, utilise par exemple SwingUtilities.invokeLater(Runnable runnable) ou bien utilise carrément un SwingWorker. Il faut absolument éviter de manipuler des objets Swing et AWT en dehors de l'EDT.















TUER : http://tuer.sourceforge.net/tuer.jnlp

yeah! vive java
0
SpaceHam Messages postés 78 Date d'inscription lundi 27 mars 2006 Statut Membre Dernière intervention 22 octobre 2015
9 déc. 2010 à 14:55
Je vais tenter de créer un runnable comme tu me demande... Je reviens par la suite avec mon résultat.


SpaceHamAgent
0
SpaceHam Messages postés 78 Date d'inscription lundi 27 mars 2006 Statut Membre Dernière intervention 22 octobre 2015
9 déc. 2010 à 14:55
Je vais tenter de créer un runnable comme tu me demande... Je reviens par la suite avec mon résultat.


SpaceHamAgent
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
SpaceHam Messages postés 78 Date d'inscription lundi 27 mars 2006 Statut Membre Dernière intervention 22 octobre 2015
9 déc. 2010 à 16:36
J'ai tenté à la place de me créer une classe qui implemente Runnable. Aurais-tu un exemple simple afin de ne pas jouer avec AWT.


En gros je pars ma classe ainsi :

UpdateViewList uvl = new UpdateViewList(this);
thUpdate = new Thread(uvl);
thUpdate.start();

Le problème aussi c'est que ma JList n'arrête pas de se mettre à jour et il est donc difficile de sélectionner un usager de ma liste afin d,envoyer un message privé. à moins d'envoyer un Sleep au Thread.

UpdateViewList.java
-----------------------------------------
import lc.cc.CPrincLC;//mon controleur

public class UpdateViewList implements Runnable
{
private CPrincLC cc = null;
private boolean update = true;
private int nb = 0;

public UpdateViewList(CPrincLC cont)
{
cc = cont;
}
public void run()
{
while(update)
{
cc.updateAllUsersConnect();
nb++;
// update = false;
System.out.println("runnable #"+nb);
}
}
}
-----------------------------------------

Encore l'exception

--------------------------------------------
runnable #1090
runnable #1091
runnable #1092
runnable #1093
Exception occurred during event dispatching:
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicListUI.paintImpl(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at javax.swing.JOptionPane.showOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showConfirmDialog(Unknown Source)
at lc.utils.MsgLC.sendMsg(MsgLC.java:12)
at lc.cc.CPrincLC.windowClosing(CPrincLC.java:113)
at java.awt.Window.processWindowEvent(Unknown Source)
at javax.swing.JFrame.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)runnable #1094

at java.awt.Component.dispatchEventImpl(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.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)
runnable #1095
--------------------------------------------

SpaceHamAgent
0
SpaceHam Messages postés 78 Date d'inscription lundi 27 mars 2006 Statut Membre Dernière intervention 22 octobre 2015
9 déc. 2010 à 16:36
J'ai tenté à la place de me créer une classe qui implemente Runnable. Aurais-tu un exemple simple afin de ne pas jouer avec AWT.


En gros je pars ma classe ainsi :

UpdateViewList uvl = new UpdateViewList(this);
thUpdate = new Thread(uvl);
thUpdate.start();

Le problème aussi c'est que ma JList n'arrête pas de se mettre à jour et il est donc difficile de sélectionner un usager de ma liste afin d,envoyer un message privé. à moins d'envoyer un Sleep au Thread.

UpdateViewList.java
-----------------------------------------
import lc.cc.CPrincLC;//mon controleur

public class UpdateViewList implements Runnable
{
private CPrincLC cc = null;
private boolean update = true;
private int nb = 0;

public UpdateViewList(CPrincLC cont)
{
cc = cont;
}
public void run()
{
while(update)
{
cc.updateAllUsersConnect();
nb++;
// update = false;
System.out.println("runnable #"+nb);
}
}
}
-----------------------------------------

Encore l'exception

--------------------------------------------
runnable #1090
runnable #1091
runnable #1092
runnable #1093
Exception occurred during event dispatching:
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicListUI.paintImpl(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at javax.swing.JOptionPane.showOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showConfirmDialog(Unknown Source)
at lc.utils.MsgLC.sendMsg(MsgLC.java:12)
at lc.cc.CPrincLC.windowClosing(CPrincLC.java:113)
at java.awt.Window.processWindowEvent(Unknown Source)
at javax.swing.JFrame.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)runnable #1094

at java.awt.Component.dispatchEventImpl(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.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)
runnable #1095
--------------------------------------------

SpaceHamAgent
0
SpaceHam Messages postés 78 Date d'inscription lundi 27 mars 2006 Statut Membre Dernière intervention 22 octobre 2015
9 déc. 2010 à 20:54
Merci de ta réponse, au moins les Exceptions devrait arrêter... juste tanant que le JList lorsqu'il se rafraichit ne conserve pas l'élément sélectioner. Il va probablement juste falloir que je m'organise pour en prendre la sélection avant de tout effacer et de le resélectionner une fois que le tout va être en place.

Encore une fois Merci! :)

SpaceHamAgent
0
Utilisateur anonyme
9 déc. 2010 à 22:38
Oui c'est cela mais stocke une information qui identifie bien l'élément sélectionné, pas juste l'indice sinon tu vas sélectionner le mauvais élément si la liste a été modifiée de telle sorte que les indices des objets ont changé.















TUER : http://tuer.sourceforge.net/tuer.jnlp

yeah! vive java
0
Rejoignez-nous