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

import of classes fails

package '…' does not exits

GhostIn Shell
GhostIn Shell
1,967 Points

I am assuming this person had the same problems as I was having. Please help. Below is the error I receive in the Workspace.

The folders go as follows. Java Data Structure then com then teamtreehouse then model. I have the two files under model Song.java and SongBook.java. Then there is Karaoke.java which I am assuming is under Java Data Structures

Karaoke.java:1: error: package com.teamtreehouse.model does not exist
import com.teamtreehouse.model.Song;
^
Karaoke.java:2: error: package com.teamtreehouse.model does not exist
import com.teamtreehouse.model.SongBook;

package com.teamtreehouse.model;

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

public class SongBook {
  private List<Song> mSongs;

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

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

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

package com.teamtreehouse.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 videoUrl; 
  }


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

}

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=SaEC9i9Q0vk");
    SongBook songBook = new SongBook();
    System.out.printf("adding %s %n", song);
    songBook.addSong(song);
    System.out.printf("There are %d songs. %n", songBook.getSongCount());
  }
}

1 Answer

Hello! Please post your code so we can help you. Without looking at your code, we can't really know what went wrong. The most likely cause in this case is a typo in the import statement, but I can't say without looking at it.