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

Shane Crosby maccroz at gmail.com
Thu Aug 9 21:11:10 EDT 2007


The error in your subject is an error from Eclipse, not from the javac
compiler.  Make sure that your project is configured to use the 1.6 JDK for
checking your syntax.  It can be found here: Window --> Preferences --> Java
--> Compiler.  Under JDK compliance make sure it says 6.0.

Chances are you've got it configured to use the 1.4 builder still and
Eclipse is barfing because 1.4 didn't have varargs or autoboxing.

On 8/9/07, Christopher Fowler <cfowler at outpostsentinel.com> wrote:
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.ajug.org/pipermail/ajug-members/attachments/20070809/4093716c/attachment.html 


More information about the ajug-members mailing list