Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
    }
}
like image 330
user2343208 Avatar asked Jul 26 '13 12:07

user2343208


People also ask

What is Java Util MissingFormatArgumentException?

The MissingFormatArgumentException is an unchecked exception in Java that occurs when a format specifier does not have a corresponding argument or if an argument index points to an argument that does not exist.

What is string format in Java?

In java, String format() method returns a formatted string using the given locale, specified format string, and arguments. We can concatenate the strings using this method and at the same time, we can format the output concatenated string. Syntax: There is two types of string format() method.


1 Answers

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.

like image 110
Uwe Plonus Avatar answered Oct 13 '22 13:10

Uwe Plonus