Salut à tous,
Lors de l'exécution de mon programme, j'ai un java.lang.NullPointerException et je ne comprends pas pourquoi... Pouvez vous m'aider??
btnJ1 est donc un tableau de bouton que je crée lorsque je les créer
Voici mon code :
package graphique;
import java.awt.Color;
import javax.swing.JButton;
public class Autres {
Fenetre2 fen;
public void Bateau(String [][] grille, int nbre, int ligne, int colonne, int coordonnee,int joueur){
int erreur = 0 ;
switch (coordonnee) {
case 1 :
for(int j = colonne ; j < colonne + nbre ; j++) {
grille[ligne][j] = "Bateau"+nbre ;
System.out.println(grille[ligne][j]);
fen.btnJ1[ligne][j].setBackground(Color.RED);
<---- (L'erreur se produit à cette ligne) //fen.grille(joueur,ligne,j);
}
break ;
case 2 :
for(int j = ligne ; j < ligne + nbre ; j++){
grille[j][colonne] = "Bateau"+nbre ;
fen.btnJ1[j][colonne].setBackground(Color.RED);
}
break ;
}
}
}
Voici le résultat de l'erreur:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at graphique.Methodes.Bateau(Methodes.java:18)
at graphique.Ecouteur.actionPerformed(Ecouteur.java:92)
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)