• Post Reply Bookmark Topic Watch Topic
  • New Topic

printf error when using eclipse  RSS feed

 
Greg Stevens
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use a printf statement similar to this:


I get the following error:


I suspect this has something to do with my Eclipse setup because when I compile the same
code from the command line, it compiles and runs fine.

Thanks in advance for any advice.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
welcome to JavaRanch.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,

maybe your eclipse compiler setting is set to 1.4 ... as far as i'm concerned primitives are not wrappered in java versions prior to 5 ...

so, either change your compiler setting anything that is highter than 1.4 (you can do that by clicking on your project in the package explorer, tne build path and configure build path, there should be a compiler setting panel) ..

or wrapper your primitive like this'

System.out.printf("... $d ...", new Integer(total));
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sebastian Janisch wrote:or wrapper your primitive like this'

System.out.printf("... $d ...", new Integer(total));

Stop using "new Integer" right now. Integer.valueOf is better, since it will use the cache (from -127 to 128) if applicable. In fact, Stop using constructors for all primitive type wrappers - they now all have valueOf methods.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay fair enough ... i give in to that :-)
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If "total" was an int, why change it? Anyway, that isn't what the thread is about; you gave an answer earlier, which is probably correct, about Java 1.4.
 
Greg Stevens
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is encouraging to see such prompt and helpful replies. This matter was resolved when, as suggested by Sebastian Janisch, I changed the compiler settings. As suspected, it was set to 1.4. When I changed it to 6.0, I no longer had the printf compiler error. For the sake of completeness, I also tried using new Integer(value) and I still got the printf error. Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!