parseFloat problems

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

--------------------Configuration: j2sdk1.4.2_04 --------------------
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 :slight_smile:

because elementAt returns Object not String. You need to cast it.

how?

i’ve tried doing a toString() but it didn’t work

(String)coords.elementAt(x)

I’ll try to sound as diplomatic as possible, but how are you planning on displaying 3D graphics and loading models in a language where you don’t understand the basics?

Float x1 = Float.parseFloat(coords.elementAt(x));

… ::slight_smile:

Float.parseFloat(someString) returns a float and not a Float.

i’m sorry but i’ve been given this as a project and i’m just trying to do the best i can so that it gets handed in on time

It’s this time of year again :slight_smile: Frantic students flooding the forums before their project have to be turned in.

Good luck! When is the deadline?

got until just after new year but i’ve only just got my models to load in and now that i’m having performance problems i decided to use a display list and now nothing works!!! :frowning:

keep getting the following error and i dont know why!

org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
at org.lwjgl.opengl.Util.checkGLError(Unknown Source)
at org.lwjgl.opengl.Display.update(Unknown Source)
at OpenGLWindow.run(OpenGLWindow.java:49)
at OpenGLWindow.main(OpenGLWindow.java:39)
Press any key to continue…

arrgh!

Is there some reason you don’t want to use a scene graph, it’d be much quicker and examples already exist to follow?

Kev