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
Benjamin Young
5,881 PointsI received a very odd error in Java.
Here is my error:
javac Karaoke.java && java Karaoke
./com/teamtreehouse/model/SongBook.java:10: error: -> expected
mSongs = newArrayList<Song>();
^
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=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());
}
}
Song.java
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 mVideoUrl;
}
@Override
public String toString() {
return String.format("Song: %s by %s", mTitle, mArtist);
}
}
SongBook.java
package com.teamtreehouse.model;
import java.util.ArrayList;
import java.util.List;
public class SongBook{
private List<Song> mSongs;
public SongBook() {
mSongs = newArrayList<Song>();
}
public void addSong(Song song) {
mSong.add(song);
}
public int getSongCount() {
return mSongs.size();
}
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! I'm no Java expert by any means, but I have a feeling that this line:
public SongBook() {
mSongs = newArrayList<Song>();
}
is missing a space. I feel fairly sure that it should be:
public SongBook() {
mSongs = new ArrayList<Song>();
}
Hope this helps!
Benjamin Young
5,881 PointsBenjamin Young
5,881 PointsWhat a silly thing to miss! Thank you for pointing that out!