![]() |
printf Problem
:
String str = new String( "Java is object oriented.");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) |
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. |
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. |
Quote:
|
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? |
try running your code thru command line
:
C:\>javac Test.javaif 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'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.javaActually 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. |
well you know its Eclipse not anything else. double check paths and settings.
try NetBeans? |
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:
|
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.
|
| All times are GMT -5. The time now is 1:56 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC