Java Java Data Structures Organizing Data Interfaces

Mher Allahverdi
Mher Allahverdi
1,686 Points

What went wrong here?

https://w.trhou.se/f5czmodi22

Javac Example.java didn't have any issues with the code but something went wrong as soon as you run it:

This is a new Treet: 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.Treet.toString(Treet.java:18)
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 Example.main(Example.java:24)

Also can someone show me how to link my code properly like other people's questions :]? I mean the snapshot works too but it seems like everyone posts their questions the other way.

2 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 47,493 Points

In Treet.java you have a + instead of a comma before mDescription here:

@Override
  public String toString () {
   return String.format ("Treet: \"%s\" by %s on %s", 
     mDescription, mAuthor, mCreationDate); 
  }
Mher Allahverdi
Mher Allahverdi
1,686 Points

Awesome! Thank you very much Kris :D

Jason Anders
MOD
Jason Anders
Treehouse Moderator 143,925 Points

Hi Mher Allahverdi

[edited]

To format code for the Community, you'll need to use Markdown. There is a Cheatsheet link above the Post button, or you can take the quick Markdown Basics Course here on Treehouse.

Hope you get it solved soon.

:) :dizzy: