Problème Erreur Exception in thread "main" java.lang.StackOverflowError
Bonjour, j'ai essayer de créer une calculatrice en java mais je rencontre l'erreur :
Exception in thread "main" java.lang.StackOverflowError
D'après les recherches que j'ai faites, cette erreur ce produit quand il y a une boucle infini qui appelle plusieurs fois un constructeur. Sauf que (je crois) que ce n'est pas le cas dans mon programme.(ou alors je ne trouve pas ou).
LA CLASSE CALCULATRICE ET SON CONSTRUCTEUR
Code:
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
| public class Calculatrice extends Frame implements WindowListener{//1
private MonPad Pad;//2
private MesOpe Ope;
private MesRes Res;
private Label Ecran;
String chiffre1;
String chiffre2;
int res;
public Calculatrice(){
super("Calculatrice");
Pad= new MonPad();
Ope= new MesOpe();
Res= new MesRes();
Ecran= new Label("");
setLayout(new GridLayout(2,3));//3
add(Ecran);
add(Pad);
add(Ope);
add(Res);
this.addWindowListener(this);
} |
LA CLASSE MONPAD ET SON CONSTRUCTEUR
Code:
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| public class MonPad extends Calculatrice implements ActionListener{ //1
private Button b0; //2
private Button b1;
private Button b2;
private Button b3;
private Button b4;
private Button b5;
private Button b6;
private Button b7;
private Button b8;
private Button b9;
private Label l1;
private Label l2;
public MonPad(){
b0=new Button ("0");
b1=new Button ("1");
b2=new Button ("2");
b3=new Button ("3");
b4=new Button ("4");
b5=new Button ("5");
b6=new Button ("6");
b7=new Button ("7");
b8=new Button ("8");
b9=new Button ("9");
l1=new Label("");
l2=new Label("");
setLayout(new GridLayout(4,3)); //3
add(b7);
add(b8);
add(b9);
add(b4);
add(b5);
add(b6);
add(b1);
add(b2);
add(b3);
add(l1);
add(b0);
add(l2);
b0.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
} |
LES ERREURS
Exception in thread "main" java.lang.StackOverflowError
at sun.awt.Win32GraphicsConfig.getBounds(Native Method)
at sun.awt.Win32GraphicsConfig.getBounds(Unknown Source)
at java.awt.Window.init(Unknown Source)
at java.awt.Window.<init>(Unknown Source)
at java.awt.Frame.<init>(Unknown Source)
at java.awt.Frame.<init>(Unknown Source)
at Calculatrice.<init>(Calculatrice.java:16)
at MonPad.<init>(MonPad.java:21)
at Calculatrice.<init>(Calculatrice.java:19)
at MonPad.<init>(MonPad.java:21)
at Calculatrice.<init>(Calculatrice.java:19)
at MonPad.<init>(MonPad.java:21)
...
Merci d'avance.