Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

java - 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.

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

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...