Help with Surface-Of-Revolution

I am trying to do a surface-of-revolution and display the object as a wireframe representation, rotating around and saving the points

It has no compile errors, but it has a runtime error in the black screen saying:

java.lang.NullPointerException
at Rotation6$Renderer.display(Rotation6.java:205)
at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.ja
va:74)
at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:194)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:192)
at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:182)
at net.java.games.jogl.GLCanvas.display(GLCanvas.java:82)
at net.java.games.jogl.Animator$1.run(Animator.java:104)
at java.lang.Thread.run(Thread.java:536)

how do I fix this problem?


here is the code

import java.awt.;
import java.awt.event.
;
import java.nio.IntBuffer;
import net.java.games.jogl.;
import net.java.games.jogl.util.
;

public class Rotation6

{

static Animator animator = null;

public static void main(String[] args)

{

Frame frame = new Frame("Rotation ");

GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

canvas.addGLEventListener(new Renderer());

frame.add(canvas);

frame.setSize(500, 500);

animator = new Animator(canvas);

frame.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

animator.stop();

System.exit(0);

}

});

frame.show();

animator.start();

canvas.requestFocus();

} // end main

static class Renderer implements GLEventListener, KeyListener {

private float rtri = 0.0f;

public class wcPt3D {

  public float x, y, z;

  

  wcPt3D(float xcoord, float ycoord, float zcoord){

        x= xcoord;

        y= ycoord;
          
        z= zcoord;

 }

 

 wcPt3D( ){

 x = 0.0f;

 y = 0.0f;
 
 z = 0.0f;

  }

} // end wcpt3d

public void init(GLDrawable gLDrawable)

{

final GL gl = gLDrawable.getGL();

final GLU glu = gLDrawable.getGLU();

gl.glMatrixMode (GL.GL_PROJECTION);

gl.glClearColor (1.0f, 0.0f, 0.0f, 0.0f); //set background to white

gl.glClearDepth(1.0f); // Depth Buffer Setup

gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing

gl.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do

gl.glOrtho (-2.0, 2.0, -2.0, 2.0, -15.0, 15.0); // define drawing area
gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f);

gLDrawable.addKeyListener(this);

}

public void keyReleased(KeyEvent e) {}

public void keyTyped(KeyEvent e) {}

public void display(GLDrawable gLDrawable)

{

final GL gl = gLDrawable.getGL();

final GLU glu = gLDrawable.getGLU();

gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Set display window to color.

gl.glMatrixMode (GL.GL_MODELVIEW);

gl.glLoadIdentity();

gl.glRotatef(rtri, 0.0f, 2.0f, 0.0f);

gl.glBegin(GL.GL_LINES); //drawing using lines

wcPt3D[][] p1 = new wcPt3D[10][36];

float angle=0.0f;

  int i =0;

p1[0][0] =new wcPt3D (0.150f, 0.750f, 0.000f);
p1[1][0] =new wcPt3D (0.450f, 0.750f, 0.000f);
p1[2][0] =new wcPt3D (0.450f, 0.750f, 0.000f);
p1[3][0] =new wcPt3D (0.650f, 0.500f, 0.000f);
p1[4][0] =new wcPt3D (0.650f, 0.500f, 0.000f);
p1[5][0] =new wcPt3D (0.350f, 0.350f, 0.000f);
p1[6][0] =new wcPt3D (0.350f, 0.350f, 0.000f);
p1[7][0] =new wcPt3D (0.150f, 0.350f, 0.000f);
p1[8][0] =new wcPt3D (0.150f, 0.350f, 0.000f);
p1[9][0] =new wcPt3D (0.150f, 0.150f, 0.000f);

for (int row = 0; row < 36; row++) {
gl.glBegin(GL.GL_LINES);

     for (int col = 0; col < 10; col++) {
        gl.glVertex3f(p1[row][col].x, p1[row][col].y, p1[row][col].z);



  }

gl.glEnd();
}

/*gl.glVertex3f(0.150f, 0.750f, 0.000f);
gl.glVertex3f(0.450f, 0.750f, 0.000f);
gl.glVertex3f(0.450f, 0.750f, 0.000f);
gl.glVertex3f(0.650f, 0.500f, 0.000f);
gl.glVertex3f(0.650f, 0.500f, 0.000f);
gl.glVertex3f(0.350f, 0.350f, 0.000f);
gl.glVertex3f(0.350f, 0.350f, 0.000f);
gl.glVertex3f(0.150f, 0.350f, 0.000f);
gl.glVertex3f(0.150f, 0.350f, 0.000f);
gl.glVertex3f(0.150f, 0.150f, 0.000f);
*/

gl.glEnd(); // Finished

rtri += 0.2f;

//}
gl.glFlush();
}

public void displayChanged(GLDrawable gLDrawable, boolean modeChanged, boolean deviceChanged)

{

}

public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height)

{

}
public void keyPressed(KeyEvent e)

{

if (e.getKeyCode() == KeyEvent.VK_ESCAPE)

animator.stop();

System.exit(0);

}

public void rotate3D (wcPt3D[][] p1)

{

float deg = 0;
float RadianAngle = (float)(180/Math.PI);

  for (int row = 0; row < 36; row++) {
  

  for (int col = 0; col < 10; col++) {
  
float zp = p1[row][col].z * (float)Math.cos(deg * RadianAngle) - p1[row][col].x * (float)Math.sin(deg * RadianAngle);
float xp = p1[row][col].z * (float)Math.sin(deg * RadianAngle) + p1[row][col].x * (float)Math.cos(deg * RadianAngle);
float yp = p1[row][col].y;

p1[row][col] = new wcPt3D(xp, yp, zp);

deg += 10.0f;

}
 
  }
       
 }

public void draw3D (wcPt3D[][] p1, GL gl)

{

for (int row = 0; row < 36; row++) {
gl.glBegin(GL.GL_LINES);

     for (int col = 0; col < 10; col++) {
        gl.glVertex3f(p1[row][col].x, p1[row][col].y, p1[row][col].z);
 


  }

gl.glEnd();
}

}

}

}

In this code:

gl.glBegin(GL.GL_LINES); //drawing using lines

wcPt3D[][] p1 = new wcPt3D[10][36];

float angle=0.0f;

int i =0;

p1[0][0] =new wcPt3D (0.150f, 0.750f, 0.000f);
p1[1][0] =new wcPt3D (0.450f, 0.750f, 0.000f);
p1[2][0] =new wcPt3D (0.450f, 0.750f, 0.000f);
p1[3][0] =new wcPt3D (0.650f, 0.500f, 0.000f);
p1[4][0] =new wcPt3D (0.650f, 0.500f, 0.000f);
p1[5][0] =new wcPt3D (0.350f, 0.350f, 0.000f);
p1[6][0] =new wcPt3D (0.350f, 0.350f, 0.000f);
p1[7][0] =new wcPt3D (0.150f, 0.350f, 0.000f);
p1[8][0] =new wcPt3D (0.150f, 0.350f, 0.000f);
p1[9][0] =new wcPt3D (0.150f, 0.150f, 0.000f);

for (int row = 0; row < 36; row++) {
gl.glBegin(GL.GL_LINES);

for (int col = 0; col < 10; col++) {

gl.glVertex3f(p1[row][col].x, p1[row][col].y, p1[row][col].z);

}
gl.glEnd();

You have two glBegin calls, that won’t work, remove the one inside the loop.