编译时找不到符号错误。 [英] Cannot find symbol error when compiling.
本文介绍了编译时找不到符号错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮助我在程序中找到错误吗?当我编译它时,它给出了找不到符号错误。我已经玩了一段时间,但似乎无法理解我的错误。
Can someone help me find the error in my program? When I compile it, it gives the cannot find symbol error. I have been playing around with it for a while but cant seem to grasp my mistake.
我的主类:
public static void main(String[] args) {
int plays;
SlotMac machine[] = new SlotMac[3];
machine[0] = new SlotMac(3,35,30);
machine[1] = new SlotMac(10,100,60);
machine[2] = new SlotMac(4,10,9);
plays= firstmachine(machine[0]);
System.out.println(plays);
我的其他班级:
public class SlotMac {
int win_plays, plays;
int times_played;
int quarters;
public SlotMac(int times_played, int win_plays, int quarters) {
this.win_plays= win_plays;
this.times_played= times_played;
this.quarters= quarters;
}
public int firstmachine() {
return plays;
}
}
推荐答案
没有方法 firstmachine(SlotMac obj)
所以说 firstmachine(machine [0]);
它将尝试在同一类中搜索相同的方法,但找不到。
so when you say firstmachine(machine[0]);
it will try to search the same method in the same class, which it will not find.
您需要调用以下方法
machine[0].firstmachine();
这篇关于编译时找不到符号错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文