hallo leute
ich bin grad dran mein erstes Spiel (naja eher Animation mit Bewegung und Jump
) zu programmieren...
hab das spiel soweit fertig, kann es von ner Testklasse aus starten. Aber ich wollte noch ein Menü einbauen als Intro...
wenn ich aber das Game von Actionperformed aus starten möchte geht das nicht, ich bekomme einen Grey-Fullscreen und folgenden Fehler:
die Zeilenangaben zeigen jeweils auf die draw-Methoden
und hier zum Verständnis noch bisschen Code:
Alles ist im gleichen Pkg.
Es würd mich interessieren: Warum funktioniert es nicht? Und wie kann ich es anders hinbekommen sodass es funzt???:L
lg
ich bin grad dran mein erstes Spiel (naja eher Animation mit Bewegung und Jump
hab das spiel soweit fertig, kann es von ner Testklasse aus starten. Aber ich wollte noch ein Menü einbauen als Intro...
wenn ich aber das Game von Actionperformed aus starten möchte geht das nicht, ich bekomme einen Grey-Fullscreen und folgenden Fehler:
Code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Theorie.animation_2D.ScreenManager.getGraphics(ScreenManager.java:145)
at Theorie.animation_2D.GameCore.loop(GameCore.java:63)
at Theorie.animation_2D.GameCore.run(GameCore.java:42)
at Theorie.animation_2D.Menu.startGame(Menu.java:72)
at Theorie.animation_2D.Menu$2.actionPerformed(Menu.java:65)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
die Zeilenangaben zeigen jeweils auf die draw-Methoden
und hier zum Verständnis noch bisschen Code:
Java:
public class TEST_ANIMATION {
public static void main(String[] args) {
@SuppressWarnings("unused")
Menu menu = new Menu();
// new Game().run(); // funktioniert!
}
}
Java:
public class Menu extends JFrame {
....
public Menu() {
...
// ActionListener wird als anonyme Klasse eingebunden
play.addActionListener(new ActionListener() { // JButton
// Beim Drücken des Buttons wird actionPerformed aufgerufen
public void actionPerformed(ActionEvent e) {
Menu.this.dispose();
new Game().run(); //<========= funktioniert nicht
}
});
}....
Alles ist im gleichen Pkg.
Es würd mich interessieren: Warum funktioniert es nicht? Und wie kann ich es anders hinbekommen sodass es funzt???:L
lg