After looking through multiple other questions similar, I still seem to have this problem. This seems to be the only relavent post, but it still does not answer my question. The issue I'm having is in my main function I establish a boolean, but in a function I call after that it gives me an NPE. Shown here:
public class Display extends JFrame {
private static final long serialVersionUID = 1L;
public JPanel gp = (JPanel) getGlassPane();
public Images i;
public ActualGameClass p;
public Draw d;
public Controls c;
public boolean AllLoaded = false;
public Display(){
i = new Images();
gp.setVisible(true);
c = new Controls(this, d);
c.loadControls();
p = new ActualGameClass();
d = new Draw(p, i);
i.loadImages();
System.out.println(c.ControlsLoaded);
AllLoaded = true;
gp.setLayout(new GridLayout(1, 1, 0, 0));
this.setLayout(new GridLayout(1, 1, 0, 0));
gp.add(d, p);
this.add(i);
p.Game();
}
then in the class ActualGameClass.java
public void Game(){
if(Main.f.AllLoaded){
//game
}
}
When I run this code, it points me to the
if(Main.f.AllLoaded)
saying there is an NPE.
Because it was requested and I'm having trouble formatting in the comments: Main is just what I use to set a window in JFrame here's the relevant class
public class Main {
public static Display f = new Display();
public static int w =
Main.f.ResChoiceW + 0;
public static int h =
Main.f.ResChoiceH +22; //Top Bar of GP renders as 22px
public static void main(String args[]){
f.setSize(w, h);
f.setResizable(false);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setTitle("Eddy's Adventures");
f.setLocationRelativeTo(null);
f.setAlwaysOnTop(false);
}
and the Stacktrace
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
at com.fireFlower.pasterino.ActualGameClass.Game(ActualGameClass.java:24)
at com.fireFlower.pasterino.Display.<init>(Display.java:31)
at com.fireFlower.pasterino.Main.<clinit>(Main.java:7)
.fand where isMain? Also, show the stacktrace.booleancan;t benull, butMain.fmight be.