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 trialJavier MARQUEZ
11,877 PointsI get Missing.Format.ArgumentExceptions, my code is exactly the same I uderstand everyting I am frustrated and lost :(
Could someone please take a look at my code. I get the below errors.
Adding Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '%s'
at java.util.Formatter.format(Formatter.java:2519)
at java.util.Formatter.format(Formatter.java:2455)
at java.lang.String.format(String.java:2940)
at com.teamtreehouse.model.Song.toString(Song.java:29)
at java.util.Formatter$FormatSpecifier.printString(Formatter.java:2886)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2763)
at java.util.Formatter.format(Formatter.java:2520)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at Karaoke.main(Karaoke.java:16)
I had to change the songBook() method, I was being told that I had to declare a retunr value.
Javier MARQUEZ
11,877 Pointspackage com.teamtreehouse.model;
public class Song{
private String mTitle;
private String mArtist;
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("Title : %s by %s, click here: %s", mTitle, mArtist);
}
} ```
Javier MARQUEZ
11,877 Points package com.teamtreehouse.model;
import java.util.List; //importing the list interface
import java.util.ArrayList;
public class SongBook{
private List<Song> mSongs; //empty interface "mSomething" is private
public void songBook(){
mSongs = new ArrayList<Song>(); //remember the "new" word
}
public void addSong(Song song){
mSongs.add(song);
}
public int getSongCount(){
return mSongs.size();
}
} ```
2 Answers
Simon Coates
28,694 Pointscan you try
return String.format("Title : %s by %s, click here: ", mTitle, mArtist);
think it might be expecting a fourth argument due to three instances of %s
Javier MARQUEZ
11,877 PointsAnd you were right, the string format was waiting for 3 pieces of date. Thanks you so much
Javier MARQUEZ
11,877 PointsHello I got it.
I was having an error with the constructor of the Songbook.
I had a typo here:
public songBook(){
mSongs = new ArrayList<Song>(); //remember the "new" word
}
//Constructors have the same name of the class file, CaSeSeNsItIvE!!!
public SongBook(){
mSongs = new ArrayList<Song>(); //remember the "new" word
}
Javier MARQUEZ
11,877 PointsJavier MARQUEZ
11,877 Points