please help - parseFloat probs

Started by ug02070, November 17, 2004, 21:51:24

Previous topic - Next topic

ug02070

can anyone tell me why i would be getting the following errors:-

--------------------Configuration: j2sdk1.4.2_04 <Default>--------------------
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:96: parseFloat(java.lang.String) in java.lang.Float cannot be applied to (java.lang.Object)
      Float x1 = Float.parseFloat(coords.elementAt(x));
                               ^
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:97: parseFloat(java.lang.String) in java.lang.Float cannot be applied to (java.lang.Object)
      Float y1 = Float.parseFloat(coords.elementAt(x+1));
                               ^
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:98: parseFloat(java.lang.String) in java.lang.Float cannot be applied to (java.lang.Object)
      Float z1 = Float.parseFloat(coords.elementAt(x+2));
                               ^
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:100: parseFloat(java.lang.String) in java.lang.Float cannot be applied to (java.lang.Object)
      Float x2 = Float.parseFloat(coords.elementAt(x+3));
                               ^
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:101: parseFloat(java.lang.String) in java.lang.Float cannot be applied to (java.lang.Object)
      Float y2 = Float.parseFloat(coords.elementAt(x+4));
                               ^
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:102: parseFloat(java.lang.String) in java.lang.Float cannot be applied to (java.lang.Object)
      Float z2 = Float.parseFloat(coords.elementAt(x+5));
                               ^
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:104: parseFloat(java.lang.String) in java.lang.Float cannot be applied to (java.lang.Object)
      Float x3 = Float.parseFloat(coords.elementAt(x+6));
                               ^
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:105: parseFloat(java.lang.String) in java.lang.Float cannot be applied to (java.lang.Object)
      Float y3 = Float.parseFloat(coords.elementAt(x+7));
                               ^
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:106: parseFloat(java.lang.String) in java.lang.Float cannot be applied to (java.lang.Object)
      Float z3 = Float.parseFloat(coords.elementAt(x+8));
                               ^
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:108: glVertex3f(float,float,float) in org.lwjgl.opengl.GL11 cannot be applied to (java.lang.Float,java.lang.Float,java.lang.Float)
      GL11.glVertex3f(x1, y1, z1);
                   ^
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:109: glVertex3f(float,float,float) in org.lwjgl.opengl.GL11 cannot be applied to (java.lang.Float,java.lang.Float,java.lang.Float)
      GL11.glVertex3f(x2, y2, z2);
                   ^
C:\Documents and Settings\Danny\Desktop\OpenGLWindow.java:110: glVertex3f(float,float,float) in org.lwjgl.opengl.GL11 cannot be applied to (java.lang.Float,java.lang.Float,java.lang.Float)
      GL11.glVertex3f(x3, y3, z3);
                   ^
12 errors

Process completed.


from the following code:-

GL11.glBegin(GL11.GL_TRIANGLES);

   for (int x = 0;x<coords.size();x+=9) {
      Float x1 = Float.parseFloat(coords.elementAt(x));
      Float y1 = Float.parseFloat(coords.elementAt(x+1));
      Float z1 = Float.parseFloat(coords.elementAt(x+2));
      
      Float x2 = Float.parseFloat(coords.elementAt(x+3));
      Float y2 = Float.parseFloat(coords.elementAt(x+4));
      Float z2 = Float.parseFloat(coords.elementAt(x+5));
      
      Float x3 = Float.parseFloat(coords.elementAt(x+6));
      Float y3 = Float.parseFloat(coords.elementAt(x+7));
      Float z3 = Float.parseFloat(coords.elementAt(x+8));
      
      GL11.glVertex3f(x1, y1, z1);
      GL11.glVertex3f(x2, y2, z2);
      GL11.glVertex3f(x3, y3, z3);

   }      
      GL11.glEnd();   

thanks in advance to all who reply
Danny :)

ap_kelly

You have 2 problems in the code supplied.

The first is parseFloat doesn't return a Float object, it returns a float scalar, so change the type of the x1, y1, z1 etc to be float.

The second problem you have, is that coords.elementAt(x) returns an Object, and you need to pass in a String to the parseFloat method. So you need an explicit cast or change the code to parseFloat("" + coords.elementAt(x)). In Java 1.5 you'd be able to explicit say that your Vector or whatever coords is defined as contains <String> and it will perform this cast for you.

Regards,

Andy.

ug02070

can u modify my code to show me how plz
thanks :)

ap_kelly

Something like this should work.

GL11.glBegin(GL11.GL_TRIANGLES);

for (int x = 0;x<coords.size();x+=9) {
float x1 = Float.parseFloat("" + coords.elementAt(x));
float y1 = Float.parseFloat("" + coords.elementAt(x+1));
float z1 = Float.parseFloat("" + coords.elementAt(x+2));

float x2 = Float.parseFloat("" + coords.elementAt(x+3));
float y2 = Float.parseFloat("" + coords.elementAt(x+4));
float z2 = Float.parseFloat("" + coords.elementAt(x+5));

float x3 = Float.parseFloat("" + coords.elementAt(x+6));
float y3 = Float.parseFloat("" + coords.elementAt(x+7));
float z3 = Float.parseFloat("" + coords.elementAt(x+8);

GL11.glVertex3f(x1, y1, z1);
GL11.glVertex3f(x2, y2, z2);
GL11.glVertex3f(x3, y3, z3);

}
GL11.glEnd();


You might see some performance benefit by trying to eliminate the parseFloat calls out of your render loop. Have a look at changing your design so that coords doesn't hold Strings but holds floats instead.

Andy.

the2bears

Quote from: "ug02070"can u modify my code to show me how plz
thanks :)

Wow.  Why not send the requirements doc?  No need to attempt any code on your own at all.  Someone here will surely do this for you.

Ug.  Seriously, I don't mind people asking for help, I've done it often enough myself, but you've caught me late at night, tired.  This is seems somewhat lazy on your part.

Bill

Edit: Yeah, it's late and now I feel a *little* guilty.  Just a little.  Ug, make your request in a different way.  Tell us what part of your code gives you trouble, which part you can't figure out.  At least then we'll know you're trying.
the2bears - the indie shmup blog

ug02070

sorry guys, i was a bit drunk, a bit tired and a bit annoyed with this project last night, wont happen again guys!