IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

AWT/Swing Java Discussion :

Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException


Sujet :

AWT/Swing Java

  1. #1
    Membre du Club
    Inscrit en
    Décembre 2007
    Messages
    63
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 63
    Points : 41
    Points
    41
    Par défaut Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
    Bonjour

    Après de nombreux efforts pour parvenir à afficher quelquechose avec java
    j'aboutit à ces erreurs sans vraiment parvenir à comprendre pourquoi. Si quelqu'un avait une idée...

    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
     
    Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
    	at java.util.LinkedList$ListItr.checkForComodification(Unknown Source)
    	at java.util.LinkedList$ListItr.next(Unknown Source)
    	at visualisation.JCanvas.paint(JCanvas.java:17)
    	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    	at javax.swing.BufferStrategyPaintManager.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)
    Merci beaucoup !

  2. #2
    Membre expert
    Avatar de natha
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 346
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 346
    Points : 3 083
    Points
    3 083
    Par défaut
    Tu ajoutes des éléments dans une liste qui est en cours de lecture (ou autre chose dans le genre). Sans le code de JCanvas on ne pourra t'en dire beaucoup plus.
    Comment ça ? La réponse à ton problème n'est ni dans la faq, ni dans les tutos, ni dans sources ??? Etonnant...
    De la bonne manière de poser une question (et de répondre).
    Je ne fais pas de service par MP. Merci (...de lire les règles...).
    Ma page dvp.com

  3. #3
    Membre du Club
    Inscrit en
    Décembre 2007
    Messages
    63
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 63
    Points : 41
    Points
    41
    Par défaut
    Merci pour l'indication. je vous fournit le code mais il est tellement vide que je doute qu'il soit très utile.

    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
    package visualisation;
     
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.List;
    import javax.swing.JPanel;
    import java.awt.Graphics;
     
     
    public class JCanvas extends JPanel {
     
    	private List<IDrawable> drawables = new LinkedList<IDrawable>();
     
    	public void paint(Graphics g) {
    		//for (Iterator<IDrawable> iter = drawables.iterator(); iter.hasNext();) {
    		if (!drawables.isEmpty()){
    		for (IDrawable iter : drawables){
    			IDrawable d = iter;//(IDrawable) iter.next();
    			d.draw(g);	
    		} 
    		}
     
    	}
     
    	public void addDrawable(IDrawable d) {
    		drawables.add(d);
    		repaint();
    	}
     
    	public void removeDrawable(IDrawable d) {
    		drawables.remove(d);
    		repaint();
    	}
     
    	public void clear() {
    		drawables.clear();
    		repaint();
    	}
     
    }

  4. #4
    Membre expert
    Avatar de natha
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 346
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 346
    Points : 3 083
    Points
    3 083
    Par défaut
    C'est effectivement un problème de lecture/écriture sur ta liste dans 2 threads différents. Voici un code qui devrait résoudre le prob :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    	public void paint(Graphics g) {
    		if (!drawables.isEmpty()){
    			IDrawable[] drawablesCopy = drawables.toArray(new IDrawable[drawables.size()]);.
    			for (IDrawable iter : drawablesCopy){
    				IDrawable d = iter;
    				d.draw(g);	
    			} 
    		}
    	}
    Comment ça ? La réponse à ton problème n'est ni dans la faq, ni dans les tutos, ni dans sources ??? Etonnant...
    De la bonne manière de poser une question (et de répondre).
    Je ne fais pas de service par MP. Merci (...de lire les règles...).
    Ma page dvp.com

  5. #5
    Membre du Club
    Inscrit en
    Décembre 2007
    Messages
    63
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 63
    Points : 41
    Points
    41
    Par défaut
    Effectivement c'est mieux... J'ai une autre erreur ui apparaît maintenant.
    Par ailleurs je veux afficher quelquechose pas à pas et au bout d'un moment java déide de concaténer les affichages, comment l'en empêcher ?

    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
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 39888
    	at java.util.LinkedList.toArray(Unknown Source)
    	at visualisation.JCanvas.paint(JCanvas.java:16)
    	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    	at javax.swing.BufferStrategyPaintManager.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)

  6. #6
    Membre émérite
    Avatar de gifffftane
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 354
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire (Rhône Alpes)

    Informations forums :
    Inscription : Février 2007
    Messages : 2 354
    Points : 2 582
    Points
    2 582
    Par défaut
    Est-ce que c'est une appli avec plusieurs threads ? Est-ce que tu es susceptible d'ajouter ou retirer des éléments de cette liste pendant l'affichage ?

    J'ai peur que tu ne sois obligé de faire quelques synchronisations...
    Mieux que Google, utilisez Sur Java spécialisé sur la plate-forme java !
    Pour réaliser vos applications Java dans le cadre de prestations, forfait, conseil, contactez-moi en message privé.

Discussions similaires

  1. Réponses: 9
    Dernier message: 05/06/2015, 16h48
  2. Serveur multithread - Exception : java.util.ConcurrentModificationException
    Par rXpCH dans le forum Développement Web en Java
    Réponses: 13
    Dernier message: 08/07/2009, 09h19
  3. [JDOM] Exception:Exception in thread "main" java.util.ConcurrentModificationException
    Par solawe dans le forum Format d'échange (XML, JSON...)
    Réponses: 3
    Dernier message: 10/06/2009, 18h33
  4. Réponses: 8
    Dernier message: 11/05/2006, 19h32
  5. [JDIC]Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    Par kedare dans le forum Concurrence et multi-thread
    Réponses: 4
    Dernier message: 06/05/2006, 22h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo