Hallo liebe Community,
ich habe folgendes Problem:
Ich erstelle in der Klasse Fight.java ein static JLabel namens "test".
Dieses möchte ich in zu einem JFrame, welches sich in einer void in einer anderen Klasse befindet adden.
Die Klasse mit dem JLabel:
Die Klasse mit dem JFrame:
Die JLabel inv2 und game, die ich ebenfalls adde, funktionieren. Wenn ich jedoch das JLabel test adde, kommt folgender Fehler:
Vielen Dank im Vorraus für eure Hilfe!
ich habe folgendes Problem:
Ich erstelle in der Klasse Fight.java ein static JLabel namens "test".
Dieses möchte ich in zu einem JFrame, welches sich in einer void in einer anderen Klasse befindet adden.
Die Klasse mit dem JLabel:
Java:
public class Fight {
public static JLabel test;
public Fight()
{
Music.playIntro();
Icon icon = new ImageIcon("res/fightintro.gif");
JLabel test = new JLabel(icon);
}
}
Die Klasse mit dem JFrame:
Java:
public void Gameframe(){
Game game = new Game();
JFrame frame = new JFrame("Pokemon");
Inventory inven = new Inventory();
frame.add(Inventory.inv2);
frame.add(Fight.test);
frame.add(game);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
game.start();
}
}
Die JLabel inv2 und game, die ich ebenfalls adde, funktionieren. Wenn ich jedoch das JLabel test adde, kommt folgender Fehler:
Java:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at javax.swing.JFrame.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at pokemon.Menu.Gameframe(Menu.java:354)
at pokemon.Menu$1.mousePressed(Menu.java:119)
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$500(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$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.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$JavaSecurityAccessImpl.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)
Vielen Dank im Vorraus für eure Hilfe!
Zuletzt bearbeitet von einem Moderator: