![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
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 8:02 PM. |
|
|
|
|
|
#2 |
|
Expert Programmer
|
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. |
|
|
|
|
|
#3 |
|
Expert Programmer
|
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. |
|
|
|
|
|
#4 | |
|
Expert Programmer
|
Quote:
![]() |
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#9 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
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:
|
|
|
|
|
|
|
#10 |
|
Expert Programmer
|
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 10:15 PM |
| Custom Hashing Algorithms | Sane | C | 21 | Oct 16th, 2006 9:05 PM |
| complete newbie question | melee28 | C | 36 | Sep 11th, 2005 6:48 AM |
| problem with this calculator program | designXperts.net | Java | 2 | May 23rd, 2005 6:14 AM |