[ajug-members] The method format(String, Object[]) in the type Formatter is not applicable for the arguments (String, String, int)

Christopher Mawata Christopher-Mawata at utc.edu
Sat Aug 11 12:53:17 EDT 2007


You didn't have StringBuilder in 1.4 either ... I think the code you thought you compiled in 1.4 is not actually the code you compiled.
Chris


-----Original Message-----
From: Christopher Fowler <cfowler at outpostsentinel.com>
To: "General AJUG membership forum (100-200 messages/month)" <ajug-members at ajug.org>
Date: Thu, 09 Aug 2007 19:02:32 -0400
Subject: Re: [ajug-members] The method format(String, Object[]) in the type Formatter is not applicable for the arguments (String, String, int)

I was doing this in 1.4:

String.format("%s%06d", prefix, i);

That had failed so I did a search on google and saw an example using the
Formatter class.

Here is what I'm trying:
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb, Locale.US);
formatter.format("%s%06d", perfix, i);

This works here:

StringBuilder sb = new StringBuilder();
Object a[] = { prefix, new Integer(i) };
Formatter formatter = new Formatter(sb, Locale.US);
formatter.format("%s%06d", a);
//String n = String.format("%s%06d", prefix, i);
String n = sb.toString();

Seems to me like a lot of work vs the old method.


On Thu, 2007-08-09 at 17:47 -0400, Björn Gustafsson wrote:
> Which Formatter class are you using? As I recall, java.util.Formatter
> was new in Java 1.5.  I wouldn't think they'd intentionally change its
> behavior in 1.6, so maybe the "..." syntax is broken?  I can see how
> it might also be a boxing/unboxing failure, i.e. if you repackaged the
> int as an Integer it might succeed.  (Though that'd still be a bug.)
> 
> On 8/9/07, Christopher Fowler <cfowler at outpostsentinel.com> wrote:
> > I'm compiling a program in Java 1.6 that I've always have been able to
> > compile  in 1.4.  I'm not getting this error that I'm not sure how to
> > fix:
> >
> >         formatter.format("%s%06d", prefix, i);
> >                   ^^^^^^
> > The method format(String, Object[]) in the type Formatter is not
> > applicable for the arguments (String, String, int)
> >
> > It seems to me that they've may have changed the conventions used by
> > printf to their own?
> _______________________________________________
> ajug-members mailing list
> ajug-members at ajug.org
> http://www.ajug.org/mailman/listinfo/ajug-members

_______________________________________________
ajug-members mailing list
ajug-members at ajug.org
http://www.ajug.org/mailman/listinfo/ajug-members







More information about the ajug-members mailing list