找不到符号 - 变量(错误)

Cannot find symbol - variable (Error)

我在尝试从另一个 class 调用方法并检查结果是否为 0 时遇到了这个错误。我已经尝试查看类似的帖子,但仍然可以'了解为什么会发生这种情况,因此将不胜感激任何帮助,谢谢!

代码:

歌曲数据库class:

if (song1.getFileSize = 0) {        
    System.out.println("Name of song:");
    song1.setName(console.next());

    System.out.println("Artist:");
    song1.setArtist(console.next());

    System.out.println("File size (MB):");
    song1.setFileSize(console.nextInt());

    System.out.println("Duration (seconds):");
    song1.setDuration(console.nextInt());
}

歌曲class:

private int fileSize;

public void setFileSize(int inputFileSize) {
    fileSize = inputFileSize;
}

public int getFileSize() {
    return fileSize;
}

错误发生在 if (song1.getFileSize=0) 行。

您在 getFileSize 后缺少括号。你应该写:

if(song1.getFileSize() == 0)

而不是:

if(song1.getFileSize == 0)