0 Replies Latest reply: Apr 11, 2007 6:15 AM by 807596 RSS

    Thread event error?

    807596
      The code below all works if coded seperately. I have placed in system outs to establish where the error is and its something to do with the method call. It compiles fine but when run I get this error when I click a button. As you can see I only get one print out. Have no idea what the problem could be?

      ********************************************
      event pushed block
      Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at BackgroundLayered.actionPerformed(BackgroundLayered.java:258)
      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.mouseRelease(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.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)
      ********************************************
      public class backGround
           {
           animation animationAction = new animation
           public void actionPerformed(ActionEvent event)
           {
           Bevent = event.getSource();
           if (Bevent == block)
           {
                System.out.println("event pushed block");
                animationAction.loadBlock();
                System.out.println("event pushed block after");
           }
            }
      }
      public class animation()
           {
           private final String IMAGE_BLOCK_NAME = "cowBlock";
           protected ImageIcon cowBlockImages[];
           private final int TOTAL_BLOCK_IMAGES = 2;
           
           public void loadBlock()
           {
           System.out.println("Before image declared");
           cowBlockImages = new ImageIcon[TOTAL_BLOCK_IMAGES];
           System.out.println("After image declared & before for loop");
           for (int imgBlock = 0; imgBlock<cowBlockImages.length;imgBlock++)
           {
                System.out.println("In for loop");
                cowBlockImages[imgBlock] = new ImageIcon(getClass().getResource(IMAGE_BLOCK_NAME + imgBlock+ ".gif"));
           }
           System.out.println("After for loop");
           }
      }