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.

[693 byte] By [Alucard001a] at [2007-11-27 8:01:12]
# 1

> 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?

r035198xa at 2007-7-12 19:43:16 > top of Java-index,Java Essentials,Java Programming...
# 2
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....
Alucard001a at 2007-7-12 19:43:16 > top of Java-index,Java Essentials,Java Programming...
# 3
String.format appeared in Java 1.5. Your version of Eclipse is probably configured to use a version of Java that is earlier than this. Have a look at your settings in Eclipse.
floundera at 2007-7-12 19:43:16 > top of Java-index,Java Essentials,Java Programming...
# 4

> 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.

petes1234a at 2007-7-12 19:43:16 > top of Java-index,Java Essentials,Java Programming...
# 5

>> 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

jevenkuoa at 2007-7-12 19:43:16 > top of Java-index,Java Essentials,Java Programming...