Cannot find symbol error when compiling.

此生再无相见时 提交于 2019-12-13 09:37:52

问题


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.

My main class:

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);

My other class:

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;
    }

}

回答1:


there is no method firstmachine(SlotMac obj)

so when you say firstmachine(machine[0]); it will try to search the same method in the same class, which it will not find.

you need to call the method like following

machine[0].firstmachine();


来源:https://stackoverflow.com/questions/23532713/cannot-find-symbol-error-when-compiling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!