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 trialJoshua Walczak
10,854 PointsWhy am I getting error message "cannot access SongBook"?
I have followed the video for Building the Model for the karaoke project. This is the first step. I have watched the video a few times but cannot find my error. I coded along with the video in the work space.
The error I keep getting is
Karaoke.java:2: error: cannot access SongBook
import com.teamtreehouse.model.SongBook;
^
bad source file: ./com/teamtreehouse/model/SongBook.java
file does not contain class com.teamtreehouse.model.SongBook
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
I will paste my code below
Song.java
package com.teamtreehouse.model;
public class Song { private String mArtist; private String mTitle; private String mVideoUrl;
public Song(String aritst, 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); } }
SongBook.java
package com.teamtreehoouse.model;
import java.util.List; import java.util.ArrayList;
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(); }
}
Karaoke.java
import com.teamtreehouse.model.Song; import com.teamtreehouse.model.SongBook;
public class Karaoke {
public static void main(String[] args) { Song song = new Song( "Michael Jackson", "Beat It", "https://www.youtube.com/watch?v=T2PAkPp0_bY"); SongBook songBook = new SongBook(); System.out.printf("Adding %s %n", song); songBook.addSong(song); System.out.printf("There are %d songs. %n", songBook.getSongCount()); } }
2 Answers
Brendon Butler
4,254 PointsI would have to assume that the class SongBook isnt in the folder/package named model. I would try to move it into that package if it isn't already.
Joshua Walczak
10,854 Pointsthanks for your help. SongBook was in the model package. however, i had a typo in the first line of SongBook.java
Brendon Butler
4,254 PointsAh I see it now. I assumed it was a simple mistype, but I couldn't find it haha.