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 Basics Getting Started with Java Strings and Variables

Keep getting an "Exception in thread" error message because of the '%s'

Any idea why I keep getting this error message?

Exception in thread "main" java.util.MissingFormatArgumentException: For mat specifier '%s'
at java.util.Formatter.format(Formatter.java:2519)
at java.util.Formatter.format(Formatter.java:2455)
at java.io.Console.format(Console.java:170)
at java.io.Console.printf(Console.java:209)
at Introductions.main(Introductions.java:10)

Lee Reynolds Jr.
Lee Reynolds Jr.
5,160 Points

Can you include your code so that we can help please.

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

java.util.MissingFormatArgumentException means you're missing an augment for String formatter %s. For example

console.printf("Hello, %s %s", firstName)

There're two %s in the String, but there's only one parameter firstName, so it's missing another argument for %s, hence the MissingFormatArgumentException error.

Lee Reynolds Jr.
Lee Reynolds Jr.
5,160 Points

Thanks William. You're pretty good at troubleshooting :)

William Li
William Li
Courses Plus Student 26,868 Points

:) you think so? Hah, Java is an old friend to me, took couple of Java courses while I was in college, spent a ton of time fixing nasty bugs from the Java codes I wrote myself back then.

Here is my code below. I think it's right but then again...

import java.io.Console;

public class Introductions {

public static void main(String[] args) {
    Console console = System.console();
    // Welcome to the Introductions program!  Your code goes below here
    String firstName = "Ira";
    //thisIsAnExampleOfCamelCasing
    console.printf("Hello, my name is %s\n, firstName");
    console.printf("%s is learning how to write Java\n", firstName);

} }

William Li
William Li
Courses Plus Student 26,868 Points

problem is this line

console.printf("Hello, my name is %s\n, firstName");
William Li
William Li
Courses Plus Student 26,868 Points

you need to take the firstName out of the ""

....facepalm...... lol

That's why these forums are awesome and so are you guys! thanks!

Huge help....I believe your answer improves on the code shown in the video.