W klasie Game deklaruję tablicę JLabeli, mam też tam metodę tworzącą JLabele:
public static JLabel[] answers = new JLabel[Files.dbSize];
void initLabel(JLabel jlabel, int coordX, int coordY, int width, int height, String a)
{
remove(jlabel);
jlabel.setOpaque(true);
jlabel.setFont(taskFont);
jlabel.setForeground(myFontColor);
jlabel.setBackground(myBackground);
jlabel.setLocation(coordX,coordY);
jlabel.setSize(width, height);
jlabel.setText(a);
add(jlabel);
repaint();
}//koniec initLabel
W klasie Mouse próbuję utworzyć nowy JLabel:
Window.game.initLabel(Game.answers[0],5,200,100,100,"test");
Niestety program nie współpracuje:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.desktop/java.awt.Container.remove(Container.java:1282)
at TheRoom1.Game.initLabel(Game.java:66)
at TheRoom1.Mouse.click(Mouse.java:99)
at TheRoom1.Mouse.mouseClicked(Mouse.java:16)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6581)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3343)
at java.desktop/java.awt.Component.processEvent(Component.java:6343)
at java.desktop/java.awt.Container.processEvent(Container.java:2259)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4961)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2317)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4793)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4480)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2303)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2758)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4793)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:99)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:739)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:737)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:736)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:199)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Problem tkwi gdzieś w powiązaniu z tablicą, bo jak sprawdzam na pojedynczej zmiennej JLabel to śmiga bez zarzutu. Co robię nie tak?