Strange exception in Eclipse, but not in CLI [message #66037] |
Wed, 18 May 2005 18:58 |
Eclipse User |
|
|
|
Originally posted by: andrew.fabbro.org
I'm using
* Eclipse 3.0.2
* Windows XPSP2
* Sun 1.5 Update 3 JDK.
Nearly all my attempts to use System.out.printf() throw the same
exception...even when I'm copying examples directly off web sites or
pasting them from the JDK 1.5's docs. The strange thing is that only
Eclipse is throwing these errors, not the underlying javac/java, because
if I compile and run at the command-line outside of Eclipse, the code
works fine.
Code is below. Here is the exception:
Exception in thread "main" java.lang.Error: Unresolved compilation
problems:
The method printf(String, Object[]) in the type PrintStream is not
applicable for the arguments (String, String, String)
The method printf(String, Object[]) in the type PrintStream is not
applicable for the arguments (String, double)
The method printf(String, Object[]) in the type PrintStream is not
applicable for the arguments (String, double, double)
at TestPrintf.main(TestPrintf.java:34)
My first thought was perhaps Eclipse was pointed at the wrong JDK, but
* 1.5 Update 3 is the only JDK on the box
* Eclipse's About says that's the JDK it's using
* All my other 1.5-specific code works fine
* looking at the rt.jar Eclipse attached, it's 1.5
So...I'm confused. Here is the code, which is in a new project all by
itself, with nothing in the build class except the usual run-time:
public class TestPrintf {
public static void main(String[] args) {
String title = "Office Manager";
String name = "David Brent";
/*
* This works
*/
Object[] o = { title, name };
System.out.printf("employee: %s %s\n", o);
/*
* This gives the exception:
*/
System.out.printf("employee: %s %s\n", title, name );
/*
* These are published examples that throws the same exception
*/
double pi = Math.PI;
System.out.printf ("pi = %5.3f%n\n", pi);
System.out.printf ("pi = %5.3f, e = %5.4f %n\n", Math.PI, Math.E);
}
}
|
|
|
|
Re: Strange exception in Eclipse, but not in CLI [message #66595 is a reply to message #66208] |
Thu, 19 May 2005 13:52 |
Eclipse User |
|
|
|
Originally posted by: wegener.cboenospam.com
You need to use 1.5 language features to call the printf method. Eclipse
3.0.x does not support 1.5 language features. 3.1M7 does. However, you
need to enable 1.5 compiler compliance in the Java->Complier->Compliance
settings for either your workspace or the project
|
|
|
|
Powered by
FUDForum. Page generated in 0.05786 seconds