title: Slidepuzzle, switch Icons
body: <p>We are making a slidepuzzle in java using Eclipse. We have put <code>Icon</code>s on buttons. Now we want to switch the <code>Icon</code> of the button we click on with the icon of the so called 'Empty button'.</p>
  
  <pre><code>int location =(new Integer(e.getActionCommand())).intValue(); //The buttons are in an Array:  "Pieces[]", Location: index
  if (Bounds(location,InvisibleButton)) {
  //The method Bounds, is one we made to see if the two pieces are next to eachother,
  Icon temp;  //Temporar ButtonIcon
  temp=Knop[location].getIcon(); 
  Pieces[location].setIcon(Piece[InvisibleButton].getIcon()); 
  Pieces[InvisibleButton].setIcon(temp); 
  InvisibleButton = location; 
  }
  </code></pre>
  
  <p>Why don't the Icons switch places?</p>
  
  <p>Errors:</p>
  
  <p>It only gives an error when we click on a piece next to the empty piece, we can click all others. The code works but it breaks the moment we want to switch the images.
  here is the error code:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  at Mozaiq.Schuifpuzzelpaneel.actionPerformed(Schuifpuzzelpaneel.java:93)
  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
  at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
  at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
  at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
  at     javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
  at java.awt.Component.processMouseEvent(Component.java:6382)
  at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
  at java.awt.Component.processEvent(Component.java:6147)
  at java.awt.Container.processEvent(Container.java:2083)
  at java.awt.Component.dispatchEventImpl(Component.java:4744)
  at java.awt.Container.dispatchEventImpl(Container.java:2141)
  at java.awt.Component.dispatchEvent(Component.java:4572)
  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4619)
  at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4280)
  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4210)
  at java.awt.Container.dispatchEventImpl(Container.java:2127)
  at java.awt.Window.dispatchEventImpl(Window.java:2489)
  at java.awt.Component.dispatchEvent(Component.java:4572)
  at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:710)
  at java.awt.EventQueue.access$400(EventQueue.java:82)
  at java.awt.EventQueue$2.run(EventQueue.java:669)
  at java.awt.EventQueue$2.run(EventQueue.java:667)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
  at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
  at java.awt.EventQueue$3.run(EventQueue.java:683)
  at java.awt.EventQueue$3.run(EventQueue.java:681)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:680)
  at     java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
  at     java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
  </code></pre>