i keep getting this "Error:cannot find symbol" on line 44 and i cant figure out what symbol im missing. im sure that all my variables are declared. Can someone help me find the problem in my code?
class personne{
private String naissance;
private int nbCafe;
public personne(String year, int number){
naissance=year;
nbCafe=number;
}
public personne(String year){
naissance=year;
nbCafe=1;
}
public String getnaissance(){
return naissance;
}
public int getnbCafe(){
return nbCafe;
}
public void afficher(String message){
System.out.println(message+ ": nee le 16 novembre 1994, consomme 2 tasse(s) de cafe");
}
public void affichertable(personne [] table, int amount,String message){
System.out.printf("Contenu du tableau de %d personne(s) %s", amount,message);
System.out.printf("Naissance nbCafe");
for (int i=0; i<amount;i++)
System.out.printf("%6.2s %8.2d\n", table[i].getnaissance(), table[i].getnbCafe() );
}
}
public class popo{
public static void main(String args[]){
personne p1= new personne("16/11/1994",2);
personne p2=new personne("15/12/1990");
p1.afficher("Informations de p1");
personne[] pers={ new personne("12/10/1991",3),new personne("15/10/1990",6), new personne("13/07/1993",3), new personne("05/06/1991"),new personne("16/12/1992",3)};
int nbpers=pers.length;
affichertable(pers,nbpers,"premier tableau");//This is line 44 where the error occurs
}
}
affichertable
is an instance method in personne
. You're trying to call it as if it's a static method in popo
.
You should be calling p1.affirchertable(...)
or p2.affichertable(...)
at a guess.
Alternatively, if the affirchertable
method isn't meant to depend on the state of a single instance of personne
, you should change it to a static method, and call it as:
personne.affichertable(...);
(As an aside, I'd strongly advise you to follow normal Java naming conventions and capitalize your class names - and put different classes in different source files.)
See more on this question at Stackoverflow