Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '10s'
Asked Answered
T

4

12

I'm no doubt missing something really obvious here but I can't figure it out. Any help would be appreciated. The mistake is coming from here:

package B00166353_Grades;

public class Student{
    String name,banner;

    public Student(String name,String banner){
        this.name=name;
        this.banner=banner;
    }

    public String toString(){
        String productDetails=new String();
        productDetails+=String.format("%-20s%10.2s%10s",this.name,this.banner);
        return productDetails;
    }
}
Tetrahedral answered 26/7, 2013 at 12:22 Comment(2)
Error is some where else. where is your main method?Deadfall
No, it's right there in toString(). Only two parameters are passed...Photoflood
F
29

Your format string "%-20s%10.2s%10s" takes three parameters:

  1. %-20s
  2. %10.2s
  3. %10s

but only supply two parameters:

  1. this.name
  2. this.banner

The error message states that the third parameter (for %10s) is missing.

So either adjust your format string or add the third parameter.

Favata answered 26/7, 2013 at 12:29 Comment(0)
P
4

You have:

productDetails+=String.format("%-20s%10.2s%10s",this.name,this.banner);

Since you have three %s in your String, format() expects three paramteres, but you only pass this.name and this.banner.

Also, since you're inside of Student, you do not need to use this. You can simply reference them by name and banner.

Photoflood answered 26/7, 2013 at 12:29 Comment(0)
O
1

You have to add an argument to the method format, because your formatted string awaits for 3 arguments, not two.

Oscitant answered 26/7, 2013 at 12:27 Comment(0)
F
0
productDetails+=String.format("%-20s%10.2s%10s",this.name,this.banner);

I think that you must pass another argument, because you pass only name and banner but in the string you have 3 times %.. try the same with only %-20s%10.2s

Flaw answered 26/7, 2013 at 12:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.