Community
Participate
Working Groups
Method printf is not recognized by Eclipse. Yet, I compile and run the same java file from the console fine.
I assume you are talking about: http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintStream.html#printf(java.lang.String,%20java.lang.Object...) Are you sure the JRE the project is compiled against is a 1.5 JRE?
(In reply to comment #1) > I assume you are talking about: > > http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintStream.html#printf(java.lang.String,%20java.lang.Object...) > > Are you sure the JRE the project is compiled against is a 1.5 JRE? Yes it is. As I said, it is compiling and running fine from the console.
What build are you using? What are your compiler settings?
The following source: public class X { public static void main(String[] args) { double x = 10.5; double y = 0.01; float z = 5.36f; System.out.printf("%f %f %f%n", x, y, z); } } returns: 10,500000 0,010000 5,360000 in build I20050331-1600. Of course you need to set your workspace and/or your project in compliance 5.0 and use a JDK 1.5. Could you please provide a test case?
import java.util.*; public class Addition { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number1; int number2; int sum; System.out.print("Enter the first number: "); number1 = input.nextInt(); System.out.print("Enter the second number: "); number2 = input.nextInt(); sum = number1 + number2; System.out.printf("Sum is %d\n", sum); } } Is returning: Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int) at Addition.main(Addition.java:33) ----------------------- If the workspace was not set properly, would it have recognized the Scanner class with no problem? In addition, if I compile and run from the console, there are no difficulties.
Your workspace is not set up properly. To recognize the scanner class, you simply need to use 1.5 class libraries. This has nothing to do with the settings of the compiler. You need to go to: Window>Preferences>Java>Compiler>JDK compliance. Put 5.0 and apply the changes. Then it works. I tried your test case on I20050331-2000 and it works like a charm. Closing as INVALID
I strongly suggest that you reopen this as a valid bug. It is NOT the Scanner class that it is having the problem..It is the PRINTF method. All parameters are set properly in the workspace. In addition, I have found others having a similar problem. I would not close this so fast.
it only seems to be happening irregulary. I am closing this bug.
It is not fixed, it was invalid as diagnosed.
closing as invalid
I had the same problem and chaged as per above comment and it proved to be invalid
So i there a fix for this or not? i have the same problem.
(In reply to Nikolai Lavroff from comment #13) > So i there a fix for this or not? i have the same problem. Invalid reports have no fix.