Simple String.format question
Hi all.
I am a newbie in Java and currently I have a problem about String.format function:
OK, the code:
import java.util.Formatter;
public class Foo5 {
public static void main(String[] args){
String s = String.format("%,d", 10000);
System.out.println(s);
}
}
Simple enough.. but not compile with this error:
The method format(String, Object[]) in the type String is not applicable for the arguments (String, int)
I am using Jre 1.6.0_01. This code is typed in Eclipse 3.2....
So, can anyone please tell me what's the problem of this code and why is it occured?
Thank you very much for all your help.
> Hi all.
>
> I am a newbie in Java and currently I have a problem
> about String.format function:
>
> OK, the code:
>
> import java.util.Formatter;
> public class Foo5 {
> public static void main(String[] args){
>
> String s = String.format("%,d", 10000);
> System.out.println(s);
> }
> }
>
> Simple enough.. but not compile with this error:
>
> The method format(String, Object[]) in the type
> String is not applicable for the arguments (String,
> int)
>
> I am using Jre 1.6.0_01. This code is typed in
> Eclipse 3.2....
>
> So, can anyone please tell me what's the problem of
> this code and why is it occured?
>
> Thank you very much for all your help.
That code should work perfectly. Are you sure it's the one you're having problems with?
> Thanks for your reply.
>
> I checked that IT WORKS using Netbeans 5.5.1, but it
> does not work in Eclipse 3.2...
>
> It's strange, but thanks anyway, I thought if this is
> a bug in Java6 at the very beginning....
Agrees w/ flounder. You are confused about the boundaries between the IDE and compiler. You need to know what is responsible for what. Eclipse and Netbeans do not change how java functions. They are only tools to help write and organize code.
>> Thanks for your reply.
>>I checked that IT WORKS using Netbeans 5.5.1, but it does not work in Eclipse 3.2...
>> It's strange, but thanks anyway, I thought if this is a bug in Java6 at the very beginning....
I think it is not a bug in Java6, just check your Eclipse setting,
try to check:
"Project"->"Properties"->"Java Compiler"
the option "Compiler compliance level" <-- set 5.0 or above