As stated above this code doesnt work when i run it (sorry for adding so many debugging comments)
public class TheBigGame extends StartingClass {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// StartingClass.main(args);
StartingClass st = new StartingClass();
st.init();
// Frame f = (Frame)(new AppletViewer(st.getWidth(),st.getHeight(), url, hshtbl, stream, avf))
// TODO code application logic here
}
}
and this is these are the line which give the error,
heliboy = getImage(getClass().getResource("heliboy.png"));
heliboy2 = getImage(getClass().getResource("heliboy2.png"));
heliboy3 = getImage(base, "heliboy3.png");
heliboy4 = getImage(base, "heliboy4.png");
heliboy5 = getImage(base, "heliboy5.png");
background = getImage(base, "background.png");
tiledirt = getImage(base, "tiledirt.png");
tilegrassTop = getImage(base, "tilegrasstop.png");
tilegrassBot = getImage(base, "tilegrassbot.png");
tilegrassLeft = getImage(base, "tilegrassleft.png");
tilegrassRight = getImage(base, "tilegrassright.png");
with this error
Exception in thread "main" java.lang.NullPointerException
at java.applet.Applet.getAppletContext(Applet.java:204)
at java.applet.Applet.getImage(Applet.java:276)
at StartingClass.init(StartingClass.java:119)
at TheBigGame.main(TheBigGame.java:26)
/home/guest/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
What i am trying to do is to run a applet named StartingClass by running its init() function from the main method of another class (this is just for testing, I will finally add this code to a jButton in a fancy jFrame). I if you have any work around without replacing the Applet (cause this is for a school project) i would gladly accept it. Right now, I'm stuck wiht the getImage function which returns a NullPointer Exception. Thanks for helping in advance.
Edit 1
This is different from this question over here as I am not interested in primarily solving a NullPointer Exception of a Image, but to improve my code by eliminating the errors. Also the link didn't solve my problem.