Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 10th, 2007, 8:52 PM   #1
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
printf Problem

String str = new String( "Java is object oriented.");
System.out.printf("|%s|%n", str);

The above code will work in "EditPlus" (which is what my college uses). While, it won't work in "Eclipse".

What would be the reason behind this?

Error:
The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, String)
__________________
Death smiles at us all. All a man can do is smile back.

Last edited by Eric the Red; Jan 10th, 2007 at 9:02 PM.
Eric the Red is offline   Reply With Quote
Old Jan 10th, 2007, 10:05 PM   #2
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
Is this all the code, and are you sure there are no differences? That's the first step.

Then, the only thing I could think of is to check to see if your compiler by passes certain things - check your settings for that, but that's a long shot (I'm Guessing). Look here for the docs page and compare again.

http://java.sun.com/j2se/1.5.0/docs/...ang.Object...)

Sorry I can't help ya more bud.
Booooze is offline   Reply With Quote
Old Jan 10th, 2007, 10:23 PM   #3
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 909
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Baffling.

The printf function of PrintStream (of which System.out is an instance) is new to Java 5. Most likely you need to update the version of Java your computer is running.

According to the documentation, your code is incorrect; the second argument to printf should be an Object array containing the "arguments referenced by the format specifiers of the format string." However, when I run your code in Eclipse on my computer, it works fine.
titaniumdecoy is offline   Reply With Quote
Old Jan 11th, 2007, 7:56 PM   #4
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
Quote:
Originally Posted by titaniumdecoy View Post
Baffling.

The printf function of PrintStream (of which System.out is an instance) is new to Java 5. Most likely you need to update the version of Java your computer is running.

According to the documentation, your code is incorrect; the second argument to printf should be an Object array containing the "arguments referenced by the format specifiers of the format string." However, when I run your code in Eclipse on my computer, it works fine.
Oops. That's the other thing I meant to mention.
Booooze is offline   Reply With Quote
Old Jan 11th, 2007, 10:19 PM   #5
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
First off, Thank you for you help.

I've tried installing the newest Java. However, it still doesn't work.

At least now I know that its not eclipse doing this. Any other ideas?
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old Jan 11th, 2007, 11:32 PM   #6
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 342
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
try running your code thru command line
C:\>javac Test.java
C:\>java Test

if javac cannot be found then set your system path to C:\Program Files\Java\jdk1.5.0_02\bin or what version you have.

im guessing Eclipse is still pointing to the older version of java. try checking to see that it is using the new javac.

btw i dont know much about java.
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Jan 12th, 2007, 1:12 AM   #7
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
I've ran my code through command line... I placed my 'String1.java' file to the root of the c drive so that.

javac C:\String1.java

Actually compiles the code without errors. However, in Eclipse I looked through the settings and found that the 'java build path' seems to be pointing to the right location. So basically, Eclipse still won't compile the code.

WOW.. I'm 100% confused.
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old Jan 12th, 2007, 12:26 PM   #8
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 342
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
well you know its Eclipse not anything else. double check paths and settings.

try NetBeans?
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Jan 12th, 2007, 12:46 PM   #9
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
IIRC, Eclipse defaults to Java 1.4 compatibility. In other words, even if you have Java 5 on your machine, by default it will compile your code as if it were for 1.4. This is why printf is not working for you.

Here is a page a quick google search pulled up. Assuming Java 5 is the only version of Java installed on your machine, then this step is the only important one:
Quote:
- Set the Eclipse>Preferences>Java>Compiler level to 5.0
If you set that option, your code should compile.
Arevos is offline   Reply With Quote
Old Jan 12th, 2007, 4:20 PM   #10
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 909
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
As I mentioned previously, according to Sun's documentation, your code is incorrect. As such, it should not be a surprise that it does not compile in some situations.
titaniumdecoy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
500 Ways to Program Numbers 1 Through 10! Sane Coder's Corner Lounge 637 Jan 5th, 2008 11:15 PM
Custom Hashing Algorithms Sane C 21 Oct 16th, 2006 10:05 PM
complete newbie question melee28 C 36 Sep 11th, 2005 7:48 AM
problem with this calculator program designXperts.net Java 2 May 23rd, 2005 7:14 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:34 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC