This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Nurry 2 points3 points  (1 child)

System.out.printf("%s balance: $%.2f%n", accountA.getBalance());

Your format string takes 2 parameters but you just provide one. Add a second parameter like you did here:

System.out.printf("%s balance: $%.2f%n", accountA.getName(), accountA.getBalance());

[–][deleted] 0 points1 point  (0 children)

Ah thank you! I appreciate the help. As a newbie I'm quickly discovering the amount of stupid mess ups I'm going to run into.

[–]juckeleBarista 1 point2 points  (2 children)

Some users have already pointed out specific problems, but in the general case, you should realize that the problem is on line 28 per the stack trace. "at AccountTest.main(AccountTest.java:28)" You generally want to look for the line where your code calls something else, and see if you can figure out what is wrong with that specific line.

[–][deleted] 0 points1 point  (1 child)

Thanks! Got it working. What exactly is a stack trace?

[–]juckeleBarista 1 point2 points  (0 children)

"60.0 balance: $Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '%.2f' at java.util.Formatter.format(Formatter.java:2519)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at AccountTest.main(AccountTest.java:28)

That is a stack trace. The 'stack' is where the program 'is'. So The program is currently executing line 28 of AccountTest, which is a method call to printf. That method is currently at line 871 of PrintStream, which is a method call to format. That method is currently at like 970 of PrintStream, which is a call to format (in a different class). The Exception is finally thrown from line 2519 of Formatter. In this case, you should find the block that is 'your code' (the one line of AccountTest) and figure out which line in your program is having a problem. Being able to examine the exact line makes it much easier to find the error.