E
E
Evgeny Petryaev2020-09-07 14:19:52
Java
Evgeny Petryaev, 2020-09-07 14:19:52

Why does this usage throw a null pointer exception?

Main class

public class Cars implements GLEventListener {
   static Scene1 scene;
 @Override
   public void init(GLAutoDrawable drawable) {
...
try {
           scene.LoadDrum(drawable);
      } catch (IOException ex) {
           Logger.getLogger(Cars.class.getName()).log(Level.SEVERE, null, ex);
      }
   }
public static void main(String[] args) {
   
      scene = new Scene1();
      scene.Scene();
Cars r = new Cars();

...
}
}

public class Scene1 { 
    class Image
    {
  int IndexTexture;
  String Name;
  int number;
    }
int Scene()
    {
  image = new Image[CountTexture];
        CountIndexTexture = 0;
        vectordrum = new Vector<String>();
        return 0;
    }
int LoadDrum(GLAutoDrawable drawable) throws IOException
    {
...

 CountIndexTexture++;
                image[CountIndexTexture - 1].Name = "auto1";
    image[CountIndexTexture - 1].number = CountIndexTexture - 1;
                image[CountIndexTexture - 1].IndexTexture = t.getTextureObject(gl);
...
}
}

an error is thrown when assigning values ​​to fields to the image array

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Petryaev, 2020-09-07
@Gremlin92

Here is the solution

private Image(int textureObject, String auto1, int i) {
        this.IndexTexture = textureObject;
        this.Name = auto1;
        this.number = i;
        }
...

                img = new Image(t.getTextureObject(gl),"auto1",CountIndexTexture - 1);
                image[CountIndexTexture - 1] = img;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question