Reputation: 80
newbie doing Java homework here. I have one class named Album which contains the following constructors:
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);
}
...}
And then I have a second class MusicCollection which instantiates the Album class thrice, within its main method...
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);
...}
However, when I attempt to compile MusicCollection.java, I get the error:
cannot find symbol
symbol : constructor Album(java.lang.String,java.lang.String,int)
location : class Album
for each time I try to call the constructor. The classes Album and MusicCollection ARE in the same directory, and Album.java compiles. I imagine I'm doing something silly, but I can't figure this out. Any help would be much appreciated!
Upvotes: 2
Views: 6374
Reputation: 2494
What Binyamin said! If you have a song class you need to say something like new Album("Debut", new Song("venus as a boy"), 3);
depending on how your Song class works, if not, change song to a string type
Upvotes: 1
Reputation: 1552
You are trying to instantiate Album with 2 strings rather than a string and some class Song
, maybe you should change the constructor to
public Album(String title, String favoriteTrack, int trackNumber) {
this.title = title;
this.favoriteTrack = favoriteTrack;
this.trackNumber = trackNumber;
artist = favoriteTrack.getArtist();
genre = favoriteTrack.getGenre();
numAlbums++;
}
or do this:
new Album("Debut", new Song("Venus as a boy"), 3);
or however Song is created.
Upvotes: 0
Reputation: 91299
You are passing a String
to the second argument of the Album
constructor, when you have declared that it should receive an instance of Song
.
Upvotes: 1
Reputation: 137312
The second argument of the constructor you defined is Song
, not String
, but in your main, you try to instantiate it with a String
as a second argument.
Upvotes: 6