printf problem

[nobr]How can i resolve this......it gives me an error that i can't resolver....i'm using netbeans 5

int total = totalRS.getInt( 1 );

// get results

sql ="SELECT surveyoption, votes, id FROM surveyresults " +

"ORDER BY id";

ResultSet resultsRS = statement.executeQuery( sql );

out.println("<title>Thank you!</title>" );

out.println("</head>" );

out.println("<body>" );

out.println("

Thank you for participating." );

out.println("<br />Results:

<pre>" );

// process results

int votes;

while ( resultsRS.next() )

{

out.print( resultsRS.getString( 1 ) );

out.print(": " );

votes = resultsRS.getInt( 2 );

out.printf("%.2f", (double ) votes / total * 100 );

out.print("% responses: " );

out.println( votes );

}// end while

init:

deps-module-jar:

deps-ear-jar:

deps-jar:

Compiling 1 source file to C:\Projects\Java2\WebApplication2\build\web\WEB-INF\classes

C:\Projects\Java2\WebApplication2\src\java\SurveyServlet.java:99: cannot find symbol

symbol : method printf(java.lang.String,double)

location: class java.io.PrintWriter

out.printf( "%.2f", ( double ) votes / total * 100 );

1 error

C:\Projects\Java2\WebApplication2\nbproject\build-impl.xml:319: The following error occurred while executing this line:

C:\Projects\Java2\WebApplication2\nbproject\build-impl.xml:143: Compile failed; see the compiler error output for details.

BUILD FAILED (total time: 1 second)[/nobr]

[2186 byte] By [pompeighuIIa] at [2007-10-3 2:40:17]
# 1
As a guess (a strong one) I would suppose that you are using java 1.4.You need to use 1.5 for printf() to be available.
jschella at 2007-7-14 19:38:38 > top of Java-index,Java Essentials,Java Programming...
# 2
i'm using java 1.5 update 7
pompeighuIIa at 2007-7-14 19:38:38 > top of Java-index,Java Essentials,Java Programming...
# 3
If you convert to printf("test") and you get the same error then the result is as I said - it isn't 1.5.If it works then it doesn't like the expression following the string.
jschella at 2007-7-14 19:38:38 > top of Java-index,Java Essentials,Java Programming...
# 4
i swear to god that i've installed java sdk 1.5.0_07do i need java ee 1.5? is that what u mean?....i think i don't need itCould it be the ide i'm using Netbeans 5.5.
pompeighuIIa at 2007-7-14 19:38:38 > top of Java-index,Java Essentials,Java Programming...
# 5

this is what netbeans 5.5 tells me

init:

deps-module-jar:

deps-ear-jar:

deps-jar:

Compiling 1 source file to C:\Projects\Java2\WebApplication2\build\web\WEB-INF\classes

C:\Projects\Java2\WebApplication2\src\java\NewClass.java:23: cannot find symbol

symbol : method printf(java.lang.String,double)

location: class java.io.PrintStream

System.out.printf ("pi = %5.3f%n", pi);

1 error

C:\Projects\Java2\WebApplication2\nbproject\build-impl.xml:319: The following error occurred while executing this line:

C:\Projects\Java2\WebApplication2\nbproject\build-impl.xml:143: Compile failed; see the compiler error output for details.

BUILD FAILED (total time: 1 second)

pompeighuIIa at 2007-7-14 19:38:38 > top of Java-index,Java Essentials,Java Programming...
# 6

> i swear to god that i've installed java sdk

> 1.5.0_07

> do i need java ee 1.5? is that what u mean?....i

> think i don't need it

> Could it be the ide i'm using Netbeans 5.5.

No swearing needed.

The fact that you have installed it does not mean that you are using it.

I have no idea how netbeans works. But at the very least I would be surprised if it used 1.5 simply because you installed it. You would have to do something to make it aware of 1.5. And there could be something else involved as well.

jschella at 2007-7-14 19:38:38 > top of Java-index,Java Essentials,Java Programming...
# 7

i think there's something wrong with build-imp.xml

here

<javac srcdir="@{srcdir}" destdir="@{destdir}" debug="@{debug}" deprecation="${javac.deprecation}" source="${javac.source}" target="${javac.target}" includeantruntime="false">

and here

<target name="-do-compile-single" depends="init,deps-jar,-pre-pre-compile">

<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>

<webproject2:javac>

<customize>

<patternset includes="${javac.includes}"/>

</customize>

</webproject2:javac>

</target>

i tested the printf creating another project in Netbeans and it worked fine...but here in a Web Application it gives those errors

pompeighuIIa at 2007-7-14 19:38:38 > top of Java-index,Java Essentials,Java Programming...
# 8

> Netbeans and it worked fine...but here in a Web

> Application it gives those errors

J2EE containers often create and compile classes during runtime. That means it must have a java compiler. And that java compiler will have a version.

There is often a way to change that compiler. That would be in the container documentation.

jschella at 2007-7-14 19:38:38 > top of Java-index,Java Essentials,Java Programming...
# 9
alright i finally fixed it......i had to change the source level in Netbeans in properties.....thanks to all!!
pompeighuIIa at 2007-7-14 19:38:38 > top of Java-index,Java Essentials,Java Programming...