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 trialIra Salem
10,331 PointsKeep 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)
2 Answers
William Li
Courses Plus Student 26,868 Pointsjava.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.
5,160 PointsThanks William. You're pretty good at troubleshooting :)
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.
Ira Salem
10,331 PointsHere 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
Courses Plus Student 26,868 Pointsproblem is this line
console.printf("Hello, my name is %s\n, firstName");
William Li
Courses Plus Student 26,868 Pointsyou need to take the firstName out of the ""
Ira Salem
10,331 Points....facepalm...... lol
That's why these forums are awesome and so are you guys! thanks!
Joe Thompson
2,343 PointsHuge help....I believe your answer improves on the code shown in the video.
Lee Reynolds Jr.
5,160 PointsLee Reynolds Jr.
5,160 PointsCan you include your code so that we can help please.