7 Replies Latest reply on Jun 26, 2007 1:24 AM by 807600

    The method format(String, Object[]) is undefined for the type String

    807600
      I have this error:
      The method format(String, Object[]) is undefined for the type String.
      What does mean that?

      import java.io.*;
      import java.util.*;


      public class Main {
      public static void main(String[] args) {

      String [] test =null;
      String str1="Today";
      String str2="is";
      String str3="monday";
      String str4="good";

      String format = "%1$-9s%2$-3s";
      format +="%3$-30s%4$-30s\n";
      test = new String[] {str1, str2, str3,str4};
      File f = new File("D:\\temp\\test.txt");

      try
      {
           if ( f.exists() )
           {

                PrintStream ps = new PrintStream(new FileOutputStream("D:\\temp\\test.txt"));
      ps.println(String.format(format,(Object[])test));
                ps.flush();
                ps.close();
           }
           else
           {
                PrintStream ps = new PrintStream(new FileOutputStream("D:\\temp\\test.txt"));
                ps.println(String.format(format,(Object[])test));
                ps.flush();
                ps.close();
           }
      }
      catch (Exception e)
      {
      System.out.println(e);
      }
      }
      }