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

Zeljko Porobija
Zeljko Porobija
11,491 Points

Exception in thread "main" java.util.UnknownFormatConversionExcept ion: Conversion = '%'

When I run my code, I get this: Exception in thread "main" java.util.UnknownFormatConversionExcept ion: Conversion = '%'
at java.util.Formatter.checkText(Formatter.java:2579)
at java.util.Formatter.parse(Formatter.java:2565)
at java.util.Formatter.format(Formatter.java:2501)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at Karaoke.main(Karaoke.java:12) Here's my code, I really cannot see the problem.

Zeljko Porobija
Zeljko Porobija
11,491 Points
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());

  }
}
Zeljko Porobija
Zeljko Porobija
11,491 Points
SongBook.java
package com.teamtreehouse.model; //helpers classes

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(); 
 }
}
Zeljko Porobija
Zeljko Porobija
11,491 Points
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);
  }
}```

2 Answers

Line 12 of Karaoke.java has a typo: should be %n not n%.

Zeljko Porobija
Zeljko Porobija
11,491 Points

I've just figured it out the moment before you posted the answer. LOL, silly me. :-) Thnx! One Best Answer for you!