Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » System.out.format
System.out.format [message #302451] Thu, 20 April 2006 17:54 Go to next message
Eclipse UserFriend
Originally posted by: kathyx.r.cordell.intel.com

Before I installed the Eclipse IDE I was using NetBeans. The following
program compiles and runs in NetBeans, but not in Eclipse. This program
came straight out of a sun tutorial. Eclipse gives me this compiler error
for every "System.out.format" line:
The method format(String, Object[]) in the type PrintStream is not
applicable for the arguments…

My question: Why does this happen with Eclipse? OR: Why does this not
happen with NetBeans?

import java.util.*;

public class NumberFormatDemo {
public static void main(String[] args) {
int n = 461012;
System.out.format("%,d%n", n);
System.out.format(Locale.FRANCE, "%08d%n", n);
System.out.format("%+8d%n", n);
System.out.format(Locale.FRANCE, "%,8d%n", n);
System.out.format("%+,8d%n%n", n);

double pi = Math.PI;
System.out.format("%f%n", pi);
System.out.format("%.3f%n", pi);
System.out.format(Locale.FRANCE, "%s,10.3f%n%n", pi * 1000);

Calendar c = Calendar.getInstance();
System.out.format("%tB %te, %tY%n", c, c, c);
System.out.format("%tl:%tM%tp%n", c, c, c);
System.out.format("%tD%n", c);
}
}

Output:
461,012
00461012
+461012
461 012
+461,012

3.141593
3.142
3141.592653589793,10.3f
Re: System.out.format [message #302454 is a reply to message #302451] Thu, 20 April 2006 18:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jefmyers.us.ibm.com

You are using a new Java feature that was introduced in Java 5.0. Make
sure you are using a Java 5.0 JRE within Eclipse, and change the
compiler compliance level in the preferences to 5.0.
Window->Preferences->Java->Compiler->Compiler compliance level.

Hope this helps,
- Jeff
Re: System.out.format [message #302457 is a reply to message #302454] Thu, 20 April 2006 19:18 Go to previous message
Eclipse UserFriend
Originally posted by: kathyx.r.cordell.intel.com

Yes, that was the answer I found. The Eclipse HELP content says “If you
start Eclipse for the first time using a J2SE 5.0 JRE, then it will use it
by default.” However, the only JRE I had (and have ever had on this PC)
was 5.0. And indeed, when I checked the Installed JRE's dialog (Windows >
Preferences > Java > Installed JRE's), it was the only one listed.

However, I also read in the HELP content: “To use the new J2SE 5.0
features, you must be working on a project that has a 5.0 compliance level
enabled. New projects can easily be marked as 5.0-compliant on the first
page of the New > Project wizard”. When I looked at that, I saw that the
radio button was checked for “Used default compiler compliance (Currently
1.4)” (So it looks like maybe the default mentioned in the first paragraph
isn't quite true.)

So I checked “Use a project specific compliance” and chose 5.0 from the
dropdown. And now I get no compile errors.
Previous Topic:Number of undo operations
Next Topic:EFS FTP Example
Goto Forum:
  


Current Time: Fri Apr 19 10:12:21 GMT 2024

Powered by FUDForum. Page generated in 0.01882 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top