I have always had problems with accessing private varibles in a class through a method to another class, for instance now i have this problem :
i have this variable in say class Hello1 :
private Item[][] bankTabs;
and i want to access it through another class say hello2, so i made a public method in Hello1 that is this :
public int amountOfItemInBank(int id) {
int amountInBank = 0;
for(int i = 0; i < bankTabs.length; i++) {
for(int i2 = 0; i2 < bankTabs[i].length; i2++) {
if (bankTabs[i][i2].getId() == id)
amountInBank = bankTabs[i][i2].getAmount();
}
}
return amountInBank;
}
but when i want to access it through Hello2, it tells me the method is not static, and when i make it static, the variable bankTabs in amountOfItemInBank do not work and i get a lot of errors.
so when i go to Hello2 class, and i try to call this method like this :
Hello1.amountOfItemInBank(50);
how can i solve this?