Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures - Retired Efficiency! Building the Model

Derek Derek
Derek Derek
8,744 Points

Questions on package

Hello,

For some reason, my SongBook.java outputs a "cannot find symbol" error. I don't think I have any typos, and I followed Craig exactly..

Below are my Song.java, SongBook.java, and the error message. Thank you for your help.

package com.hyunjaecho.model;

public class Song {
    private String mArtist;
    private String mTitle;
    private String mVideoUrl;

    public Song(String artist, String title, String videoUrl) {
        mArtist = artist;
        mTitle = title;
        mVideoUrl = videoUrl;
    }

    public String getTitle() {
        return mTitle;
    }

    public String getArtist() {
        return mArtist;
    }

    public String getVideoUrl() {
        return mVideoUrl;
    }

    @Override
    public String toString() {
        return String.format("Song: %s by %s", mTitle, mArtist);
    }

}
package com.hyunjaecho.model;

import java.util.ArrayList;
import java.util.List;

public class SongBook {
  private List<Song> mSongs;

  public SongBook() {
    mSongs = new ArrayList<Song>();
  }

  public void addSong(Song song) {
    mSongs.add(song);
  }

  public int getSongCount() {
    return mSongs.size();
  }
}

/Users/HyunJaeCho/Desktop/com/hyunjaecho/model/SongBook.java:7: error: cannot find symbol

private List<Song> mSongs; ^ symbol: class Song location: class SongBook

/Users/HyunJaeCho/Desktop/com/hyunjaecho/model/SongBook.java:13: error: cannot find symbol

public void addSong(Song song) { ^ symbol: class Song location: class SongBook

/Users/HyunJaeCho/Desktop/com/hyunjaecho/model/SongBook.java:10: error: cannot find symbol

mSongs = new ArrayList<Song>();
                       ^

symbol: class Song location: class SongBook

3 errors

[Finished in 0.6s with exit code 1]

2 Answers

That is strange, If they are in the same package you do not need to import the class. But just in case try import com.hyunjaecho.model.Song; Other than that I do not see the problem with your code.

Did Run the Code in Karaoke.java? Since there is main method in SongBook class you might be getting this error. Also one other possible reason is because you didnt import the right package in the Karaoke Class.

import com.hyunjaecho.model.Song; Import com.hyunjaecho.model.SongBook;

Try them out and run the Karaoke.java class