Exception en java

BOUDALIZ Messages postés 14 Date d'inscription mercredi 11 août 2010 Statut Membre Dernière intervention 18 août 2010 - 17 août 2010 à 17:13
cs_jojolemariole Messages postés 519 Date d'inscription mercredi 21 mars 2007 Statut Membre Dernière intervention 19 décembre 2016 - 19 août 2010 à 17:07
Bonjour,
J'ai implémenté un jeu et tout va bien sauf , parfois le programme se plante et affiche l'exception suivante
at java.awt.EventDispatchThread.run(Unknown Source)
Veuillez m'aider SVP.
Merci d'avance.

8 réponses

cs_jojolemariole Messages postés 519 Date d'inscription mercredi 21 mars 2007 Statut Membre Dernière intervention 19 décembre 2016 25
17 août 2010 à 17:34
Bonjour,

"at java.awt.EventDispatchThread.run(Unknown Source)"

n'est pas une exception, mais une ligne de la stack trace (trace de la pile) de l'exception.

Peux-tu nous donner la trace entière, qui doit ressembler à ça :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Test$1.actionPerformed(Test.java:38)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2015)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2338)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:253)
at java.awt.Component.processMouseEvent(Component.java:6430)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6195)
at java.awt.Container.processEvent(Container.java:2203)
at java.awt.Component.dispatchEventImpl(Component.java:4790)
at java.awt.Container.dispatchEventImpl(Container.java:2261)
at java.awt.Component.dispatchEvent(Component.java:4616)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4800)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4463)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4393)
at java.awt.Container.dispatchEventImpl(Container.java:2247)
at java.awt.Window.dispatchEventImpl(Window.java:2671)
at java.awt.Component.dispatchEvent(Component.java:4616)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:651)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:255)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:170)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:155)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:136)

Tout en haut, tu as le type de l'exception et le message, ensuite les appels de méthode qui ont conduit à cette exception.
La pile est affichée de haut en bas dans l'ordre chronologique inversé. Les derniers appels sont en haut, les premiers sont en bas.
En général la réponse est en haut. Donc on ne peut pas t'aider sans plus d'information.

Jonathan
0
BOUDALIZ Messages postés 14 Date d'inscription mercredi 11 août 2010 Statut Membre Dernière intervention 18 août 2010
17 août 2010 à 18:58
D'accord;Je vous remercie énormément.

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.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)
0
BOUDALIZ Messages postés 14 Date d'inscription mercredi 11 août 2010 Statut Membre Dernière intervention 18 août 2010
17 août 2010 à 19:00
Désolé, plutot c ça pourtant je n'ai pas de fautes dans les lignes mentionnées.


Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at game.SudokuJeu.backTrack(SudokuJeu.java:166)
at game.InterfaceJeu$newGame.actionPerformed(InterfaceJeu.java:522)
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.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)
0
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
18 août 2010 à 09:05
Cette erreur signifie que tu essayes de faire un liste.get(-1) ou quelque chose comme ca.

Surement un compteur mal programmé dans ton interface
0

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

Posez votre question
cs_laurent1024 Messages postés 987 Date d'inscription mardi 31 mai 2005 Statut Membre Dernière intervention 30 août 2012 25
18 août 2010 à 09:12
Bonjour
Désolé, plutot c ça pourtant je n'ai pas de fautes dans les lignes mentionnées.
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at game.SudokuJeu.backTrack(SudokuJeu.java:166)

=> Ta fonction backTrack est buggée, tu essayes d'accéder à un élément qui est à la position -1. Tu as soit un compteur qui est mal initialisé, soit une condition de boucle qui n'est pas correct, soit une ligne du genre tableau[compteur -1].


Cdt
0
cs_jojolemariole Messages postés 519 Date d'inscription mercredi 21 mars 2007 Statut Membre Dernière intervention 19 décembre 2016 25
18 août 2010 à 11:07
Salut,

En effet, à la ligne 166 de la classe SudokuJeu (dans la méthode backTrack) tu essaies d'accéder à l'index -1 d'un tableau.

Soit tu nous montres le code entier de SudokuJeu, soit tu lances ton projet en mode debug avec des points d'arrêt positionnés intelligemment afin de comprendre pourquoi l'index est à un moment valorisé à -1.

Jonathan
0
BOUDALIZ Messages postés 14 Date d'inscription mercredi 11 août 2010 Statut Membre Dernière intervention 18 août 2010
18 août 2010 à 17:03
Bonjour,
Je vous remercie pour votre aide et voici le code de SudokuJeu

package game;

import java.lang.Object;
import java.lang.Integer;
import java.lang.String;
import java.util.Random;



public class SudokuJeu
{

public boolean[] fixe;
public int[] values;
public int[] solution;
private static Random rand = new Random();

public SudokuJeu()
{
this.fixe = new boolean[81];
this.values = new int[81];
this.solution = new int[81];
}


public SudokuJeu(int n)
{
this.fixe = new boolean[81];
this.values = new int[81];
this.solution = new int[81];

for(int i=0; i<81; i++)
{
this.values[i] = 0;
}

int cases_fixes = 0;
int index;
int value;


/* choose the number of boxes to fill */

while(cases_fixes < n)
{

index = rand.nextInt(81);
if( values[index] == 0)
{
value = 1+ rand.nextInt(9);
if( ! noConflict( index, value ) )
{
value = 1 + rand.nextInt(9);
if( noConflict( index, value ) )
{
fixe[index] = true;
values[index] = value;
cases_fixes++;
}
}
else
{
fixe[index] = true;
values[index] = value;
cases_fixes++;
}

}

}


}


public void print()
{
for(int i=0; i<9; i++)
{
if( i % 3 == 0)
System.out.println("+-----------+");

for(int j=0; j<9; j++)
{
if(j % 3 == 0)
System.out.print("|");
System.out.print(this.values[i*9+j]);
}
System.out.println("|");
}
System.out.println("+-----------+");
}

public void printSolution()
{
for(int i=0; i<9; i++)
{
if( i % 3 == 0)
System.out.println("+-----------+");

for(int j=0; j<9; j++)
{
if(j % 3 == 0)
System.out.print("|");
System.out.print(this.solution[i*9+j]);
}
System.out.println("|");
}
System.out.println("+-----------+");
}


public boolean noConflict( int n, int value)
{
int i = n / 9;
int j = n % 9;
for(int k=0; k<9; k++)
{
/* teste la ligne (on itere sur les colonnes) */
if (k !j && this.values[i*9+k] value)
return false;

/* teste la colonne (on itere sur les lignes) */
if (k !i && values[k*9+j] value)
return false;
}
for( int l = i/3*3; l < i/3*3+3; l++)
for(int m = j/3*3; m < j/3*3+3; m++)
if (l!=i && m!=j && this.values[l*9+m] == value)
return false;
return true;
}

public boolean noConflictSol( int n, int value)
{
int i = n / 9;
int j = n % 9;
for(int k=0; k<9; k++)
{
/* teste la ligne (on itere sur les colonnes) */
if (k !j && solution[i*9+k] value)
return false;

/* teste la colonne (on itere sur les lignes) */
if (k !i && solution[k*9+j] value)
return false;
}
for( int l = i/3*3; l < i/3*3+3; l++)
for(int m = j/3*3; m < j/3*3+3; m++)
if (l!=i && m!=j && solution[l*9+m] == value)
return false;
return true;
}


/* returns false if no solution has been found
* returns true if a solution has been found
*/
public boolean backTrack()
{
int i;
for( i=0; i<81; solution[i] = values[i++] );

i = 0;
while(i<=80)
{
if(fixe[i])
i++;
else
{
if(solution[i] == 0)
solution[i] = 1;
else
solution[i] = solution[i]+1;

while( (! noConflictSol(i, solution[i])) && solution[i] <= 9)
solution[i]++;

if (solution[i] == 10)
{
solution[i] = 0;
i--;
while ( i>0 && fixe[i] )
--i;

/* no solution for this grid */
if(i 0 && (solution[i] 9 || fixe[i]))
{
return(false);

}
}
else
i++;
}
}

/* if we arrive here, a solution has been found */
if (i==81)
return(true);

return(false);
}



public static void main( String[] args)
{

SudokuJeu s = new SudokuJeu();
s.print();
s.backTrack();
}
}
0
cs_jojolemariole Messages postés 519 Date d'inscription mercredi 21 mars 2007 Statut Membre Dernière intervention 19 décembre 2016 25
19 août 2010 à 17:07
Bonjour,

Il nous sera difficile de corriger ton algorithme car manifestement ton algorithme comporte une erreur.

Il faudrait que tu nous expliques comment l'utiliser, comment remplir les tableaux values, fixes, solutions avant de lancer la méthode backTrack().

Par exemple, si on le lance tel quel, l'erreur ne se produit pas.
Si on met 1, 2, 3, 4, 5, 6, 7, 8, 9 sur la première ligne du tableau values, l'erreur se produit.

Avec quel exemple obtiens-tu l'erreur?
0
Rejoignez-nous