Tengo creada una clase PanelDado que extiende a JPanel, en ella asigno una imagen de un dado mediante un ImageIcon (no se si esta es la mejor manera de hacerlo pero es la única que encontré). El problema viene en que esa imagen debe cambiar al pulsar un JButton. Tengo un método setImg que me cambia la imagen pero al llamarlo desde el manejador del JButton salta la siguiente excepción.
Cita:
He comprobado que el método funciona ya que al llamarlo desde la clase en la que instancio el PanelDado funciona sin problemas. ¿Alguien sabe cual puede ser el motivo? Si necesitáis que ponga alguna parte del código concreta decírmelo y la subo. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Kinito.Interfaz$ManejadorTirada.actionPerformed(In terfaz.java:51)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2012)
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2335)
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:404)
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:253)
at java.awt.Component.processMouseEvent(Component.jav a:6268)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
at java.awt.Component.processEvent(Component.java:603 3)
at java.awt.Container.processEvent(Container.java:204 5)
at java.awt.Component.dispatchEventImpl(Component.jav a:4629)
at java.awt.Container.dispatchEventImpl(Container.jav a:2103)
at java.awt.Component.dispatchEvent(Component.java:44 55)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4633)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4297)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4227)
at java.awt.Container.dispatchEventImpl(Container.jav a:2089)
at java.awt.Window.dispatchEventImpl(Window.java:2517 )
at java.awt.Component.dispatchEvent(Component.java:44 55)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:649)
at java.awt.EventQueue.access$000(EventQueue.java:96)
at java.awt.EventQueue$1.run(EventQueue.java:608)
at java.awt.EventQueue$1.run(EventQueue.java:606)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:105)
at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:116)
at java.awt.EventQueue$2.run(EventQueue.java:622)
at java.awt.EventQueue$2.run(EventQueue.java:620)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 619)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:138)
at Kinito.Interfaz$ManejadorTirada.actionPerformed(In terfaz.java:51)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2012)
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2335)
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:404)
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:253)
at java.awt.Component.processMouseEvent(Component.jav a:6268)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
at java.awt.Component.processEvent(Component.java:603 3)
at java.awt.Container.processEvent(Container.java:204 5)
at java.awt.Component.dispatchEventImpl(Component.jav a:4629)
at java.awt.Container.dispatchEventImpl(Container.jav a:2103)
at java.awt.Component.dispatchEvent(Component.java:44 55)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4633)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4297)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4227)
at java.awt.Container.dispatchEventImpl(Container.jav a:2089)
at java.awt.Window.dispatchEventImpl(Window.java:2517 )
at java.awt.Component.dispatchEvent(Component.java:44 55)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:649)
at java.awt.EventQueue.access$000(EventQueue.java:96)
at java.awt.EventQueue$1.run(EventQueue.java:608)
at java.awt.EventQueue$1.run(EventQueue.java:606)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:105)
at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:116)
at java.awt.EventQueue$2.run(EventQueue.java:622)
at java.awt.EventQueue$2.run(EventQueue.java:620)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 619)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:138)
Saludos y muchas gracias.