Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:找不到符号(构造函数)_Java_Constructor_Compiler Errors - Fatal编程技术网

Java:找不到符号(构造函数)

Java:找不到符号(构造函数),java,constructor,compiler-errors,Java,Constructor,Compiler Errors,新手在这里做Java作业。我有一个名为Album的类,它包含以下构造函数: public class Album { private String title; private String artist; private String genre; private Song favoriteTrack; private int trackNumber; private static int numAlbums; //Construct

新手在这里做Java作业。我有一个名为Album的类,它包含以下构造函数:

public class Album {

    private String title;
    private String artist;
    private String genre;
    private Song favoriteTrack;
    private int trackNumber;
    private static int numAlbums;

    //Constructors
    public Album(String title, Song favoriteTrack, int trackNumber) {
        this.title = title;
        this.favoriteTrack = favoriteTrack;
        this.trackNumber = trackNumber;
        artist = favoriteTrack.getArtist();
        genre = favoriteTrack.getGenre();
        numAlbums++;
    }

    public Album(String title, Song favoriteTrack) {
        this(title, favoriteTrack, 1);
    }
...}
然后我有一个第二类MusicCollection,它在它的主方法中实例化了Album类三次

public static void main (String[] args) {...

    Album album1 = new Album("Debut", "Venus as a Boy", 3);
    Album album2 = new Album("Homework", "Around the World", 7);
    Album album3 = new Album("Ghost in the Machine", "Invisible Sun", 3);
    ...}
但是,当我尝试编译MusicCollection.java时,会出现以下错误:

cannot find symbol
symbol : constructor Album(java.lang.String,java.lang.String,int)
location : class Album
每次我尝试调用构造函数时。 类Album和MusicCollection位于同一目录中,并且Album.java编译。 我想我在做些傻事,但我想不出来。
任何帮助都将不胜感激

您定义的构造函数的第二个参数是
Song
,而不是
String
,但在主参数中,您尝试使用
String
作为第二个参数来实例化它。

您正在将
String
传递给
Album
构造函数的第二个参数,当您声明它应该接收一个
Song

的实例时,您试图用两个字符串而不是一个字符串和一些类
Song
实例化相册,也许您应该将构造函数更改为

public Album(String title, String favoriteTrack, int trackNumber) {
    this.title = title;
    this.favoriteTrack = favoriteTrack;
    this.trackNumber = trackNumber;
    artist = favoriteTrack.getArtist();
    genre = favoriteTrack.getGenre();
    numAlbums++;
}
或者这样做:

new Album("Debut", new Song("Venus as a boy"), 3);

还是不管这首歌是怎么创作的。

宾雅明说了什么!如果你有一个歌曲课,你需要说一些像新专辑(“处女秀”,新歌(“维纳斯是个男孩”),3)根据歌曲类的工作方式,如果没有,请将歌曲更改为字符串类型。我觉得这很傻。谢谢你的帮助!请求家庭作业帮助是可以的,但是记住要包括家庭作业标签。好的,我会记住的。可能是重复的