java.util.DuplicateFormatFlagsException

In this program we are going to do find DuplicateFormatFlagException.

Error Message:

Exception in thread "main" java.util.DuplicateFormatFlagsException: Flags = '0'
       at java.util.Formatter$Flags.parse(Formatter.java:4443)
       at java.util.Formatter$FormatSpecifier.flags(Formatter.java:2640)
       at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2709)
       at java.util.Formatter.parse(Formatter.java:2560)
       at java.util.Formatter.format(Formatter.java:2501)
       at java.util.Formatter.format(Formatter.java:2455)
       at java.lang.String.format(String.java:2940)
       at com.lib.DuplicateFormatFlagExceptions.main(DuplicateFormatFlagExceptions.java:20)


Error Description:

In this program the String format is wrong so we an error.

package com.lib;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;


public class DuplicateFormatFlagExceptions
{
            public static void main(String[] args)
      {
                 
           
                                  String str = "%1$00.2f";
                                  Object[] obj = new Object[1];
                                  obj[0] = 2d;
                                 System.out.println( String.format(str,obj));

                         }
                   
      }          
           


Error Solution:

package com.lib;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;


public class DuplicateFormatFlagExceptions
{
              public static void main(String[] args)
       {
                    
             
                                     String str = "%1$10.3f";
                                     Object[] obj = new Object[1];
                                     obj[0] = 2d;
                                    System.out.println( String.format(str,obj));

                            }
                      
       }            
             

Output:

     2.000

Share this post :

Post a comment

Please share your valuable feedback and share this article in social media.

 
Support : Ranga Rajesh Kumar
Copyright © 2019. Error Solution - All Rights Reserved
Site Designed by Ranga Rajesh Kumar