2012-02-17 4 views
2

초보자가 자바 숙제를하고 있습니다. ,자바 : 기호 (생성자)를 찾을 수 없습니다.

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

그러나 ...

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이 : 나는 다음과 같은 생성자를 포함 앨범이라는 하나 개의 클래스가 내가 생성자를 호출 할 때마다

cannot find symbol 
symbol : constructor Album(java.lang.String,java.lang.String,int) 
location : class Album 

: 나는 MusicCollection.java를 컴파일 할 때, 나는 오류가 발생합니다. Album 클래스와 MusicCollection 클래스가 같은 디렉토리에 있고 Album.java가 컴파일됩니다. 나는 어리석은 짓을하고 있다고 상상하지만이 사실을 알 수는 없다. 도움이 될 것입니다.

+0

숙제 도움말을 요청해도 숙제 태그를 포함해야합니다. – Jivings

+0

좋아, 나는 그걸 기억할 것이다. – kirky

답변

6

String이 아니라 정의한 생성자의 두 번째 인수는 String이 아니지만, 주에서는 두 번째 인수로 String으로 인스턴스화하려고합니다.

+0

Ahh. 그것이 어리석은 것으로 생각했습니다. 도와 줘서 고마워! – kirky

+0

당신은 환영합니다 :). – MByD

1

Song 인스턴스를 받아야한다고 선언하면 StringAlbum 생성자의 두 번째 인수로 전달합니다. 당신은이 개 문자열이 아닌 문자열과 일부 클래스 Song와 함께 앨범을 인스턴스화하려고

0

, 어쩌면 당신은

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

또는 그러나 노래를 만들어집니다.

1

비얀민이 말한 바에 의하면! 노래 클래스가있는 경우 노래 클래스의 작동 방식에 따라 new Album("Debut", new Song("venus as a boy"), 3);과 같은 내용이 필요합니다. 그렇지 않은 경우 노래를 문자열 유형으로 변경하십시오.

관련 문제