glGenLists throws NullPointerException

I’m creating an OBJ model loader, but whenever glGenLists() is called in my GenerateList() method, it throws a NullPointerException… why?

	public void GenerateList() {
		listID = GL11.glGenLists(1);
		GL11.glNewList(listID, GL11.GL_COMPILE);

		if (faceVertCount == 4) GL11.glBegin(GL11.GL_QUADS);
		if (faceVertCount == 3) GL11.glBegin(GL11.GL_TRIANGLES);

		for (int i=0; i<faces.size(); i++) {
			int face[][] = (int[][])(faces.elementAt(i));
			for (int j=0; j<face.length; j++) {
				float vert[] = (float[])(vertexes.elementAt(face[j][0]));
				float tex[] = (float[])(texcoords.elementAt(face[j][1]));

				GL11.glTexCoord2f(tex[0], tex[1]);
				GL11.glVertex3f(vert[0], vert[1], vert[2]);
			}
		}

		GL11.glEnd();
		GL11.glEndList();
	}

Here’s the error:

OBJECT.OBJ

266 Faces
248 Vertexes
342 Texture Coordinates
Exception in thread "main" java.lang.NullPointerException
        at org.lwjgl.opengl.GL11.glGenLists(GL11.java:1233)
        at OBJRender.GenerateList(OBJRender.java:96)
        at OBJRender.<init>(OBJRender.java:54)
        at OBJRender.main(OBJRender.java:122)

have you created a display or pbuffer first ?
you need a valid OpenGL context first

Oh, I didn’t realize I need a display setup first. I’ll try that and report back, thanks.

I noticed this with the AWTGLCanvas too, but haven’t look further for it.
Just take the my example from the lwjgl board and you will the freaking NPE :wink:

Will also report back about it.

Thank you so much, Matzon. After creating a display, it works now.

With the awt gl canvas it also still works.

How do forget creating a display? :wink:

I’m a bit confused, are you having an issue too - or have you fixed your NPE too?

Yea I had a NPE problem with my modelloader example. Not fixed yet, but now i know that it is mainly not the modelloader or rendering stuff that i have to change. The only thing that need an update is my AWTOpenGLCanvas.

As it works, the example @lwjgl.org/forum will be updated.