Bug 89912 - Method printf if not working properly
Summary: Method printf if not working properly
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 M7   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-31 18:16 EST by Charles E. Brown CLA
Modified: 2014-05-11 13:12 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Charles E. Brown CLA 2005-03-31 18:16:06 EST
Method printf is not recognized by Eclipse. Yet, I compile and run the same java
file from the console fine.
Comment 1 Rafael Chaves CLA 2005-03-31 18:21:27 EST
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?
Comment 2 Charles E. Brown CLA 2005-03-31 18:22:52 EST
(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.
Comment 3 Olivier Thomann CLA 2005-03-31 19:26:32 EST
What build are you using? What are your compiler settings?
Comment 4 Olivier Thomann CLA 2005-03-31 19:34:57 EST
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?
Comment 5 Charles E. Brown CLA 2005-03-31 21:47:33 EST
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.
Comment 6 Olivier Thomann CLA 2005-04-01 10:17:20 EST
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
Comment 7 Charles E. Brown CLA 2005-04-02 11:32:16 EST
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.
Comment 8 Charles E. Brown CLA 2005-04-02 13:05:55 EST
it only seems to be happening irregulary. I am closing this bug.
Comment 9 Philipe Mulet CLA 2005-04-03 04:14:18 EDT
It is not fixed, it was invalid as diagnosed.
Comment 10 Philipe Mulet CLA 2005-04-03 04:14:43 EDT
closing as invalid
Comment 11 Marc Cracco CLA 2006-03-02 21:59:59 EST
I had the same problem and chaged as per above comment and it proved to be invalid
Comment 12 Nikolai Lavroff CLA 2014-05-10 12:11:24 EDT
So i there a fix for this or not? i have the same problem.
Comment 13 Nikolai Lavroff CLA 2014-05-10 12:11:45 EDT
So i there a fix for this or not? i have the same problem.
Comment 14 Stephan Herrmann CLA 2014-05-11 13:12:21 EDT
(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.