Search code examples
javaarraysmethodscall

JAVA - can't call my array method


Eclipse says: 'chiffres cannot be resolved to a variable', how to fix the call method ?

public class Table {

public static void main(String[] args) {


    Tableau1 table = new Tableau1();


    table.CreerTable();
    table.AfficherTable(chiffres);

}}

part: and class Tableau1 with array: to declare it

public class Tableau1 {
int [][] chiffres;
int nombre;
public void CreerTable(){

    int[][] chiffres= {{11,01,3},
                        {12,02,4},
                        {12,03,5}};
    //edited
    this.chiffres=chiffres;


}

public int[][] AfficherTable(int[][] chiffres){
    this.nombre=12;
    for(int i=0;i<2;i++){

    System.out.println("essai"+chiffres[i][1]);
    if(chiffres[i][0]==nombre){System.out.println("ma ligne ="+chiffres[i][0]+","+chiffres[i][1]+","+chiffres[i][2]);
                                };

                        }
                        return chiffres;
}

}

Thanks a lot


Solution

  •     table.CreerTable();
        table.AfficherTable(chiffres);
    

    By resolving chiffres it searches in the Class Table as you don't specify that chiffres comes from Tableau1. Therefore the solution is:

        table.CreerTable();
        table.AfficherTable(table.chiffres);