title: Graphics drawing image backgammon game
body: <p>this is probably going to be a silly question but i am only a beginner so mercy on my soul :).
  so my problem is that i have a class called game page which is the IFrame that displays the all game.
  inside it i got a class called Board which contains a pic of the board which paints itself just fine using:</p>
  
  <pre><code>public void paintComponent(Graphics page)
  {
    super.paintComponent(page);
    page.drawImage(image, 0, 0, null);
  }
  </code></pre>
  
  <p>image is the image of the board i get it like this:</p>
  
  <pre><code>image = ImageIO.read(new File("pics/board.png"));
  </code></pre>
  
  <p>ok that works fine.
  so inside the board i also got a 2d Array of the type "Slot", Slot is another class i wrote that got a Stack of WhitePiece or Stack of BlackPiece
  those are classes i wrote representing the black or white pieces on the board.</p>
  
  <p>so in the Board class there is a method called reset board which organizes it to the start position of backgammon so it intisialize all the slots.</p>
  
  <p>now the Black and White pieces got a pic inside of the type Image which i get like this:
      pic = ImageIO.read(new File("pics/whitePiece.png"));</p>
  
  <p>now the problem is when inside reset board i call the drawSlot method from the Slot class
  it cant get the pic i think.
  i call it like this:
  first i call drawBoard:
        drawBoard(board);</p>
  
  <p>then here is drawBoard:</p>
  
  <pre><code>  public void drawBoard(Slot[][] board) throws IOException{
     for(int i=0;i&lt;2;i++){
      for(int j=0;j&lt;12;j++){
          board[i][j].drawSlot(getGraphics());
      }
     }
    }
  </code></pre>
  
  <p>and here is the problemtic method: drawSlot:</p>
  
  <pre><code>  public void drawSlot(Graphics g) throws IOException{    
    if(type == SlotType.empty){ 
        System.out.println("no type selected slot is empty Slot  Number"+slotNumber);
    }else
        if(type == SlotType.white){
          if(!wPieces.isEmpty()){
          Image pic = wPieces.pop().getPic();
          wPieces.push(new WhitePiece());
          if(slotNumber &lt;= 11){
            for(int i=0;i&lt;piecesAmount;i++){
              g.drawImage(pic, 5, i*30, null);
            }
          }
          else{
              for(int i=0;i&lt;piecesAmount;i++){
                  g.drawImage(pic, 5,300-(i*30), null);
              }
         }
          }else{
              System.out.println("Slot Stack is Empty Slot #"+slotNumber);
          }
        }else
        {
            if(!bPieces.isEmpty()){
            Image pic = bPieces.pop().getPic();
            bPieces.push(new BlackPiece());
            if(slotNumber&lt;=11){
               for(int i=0;i&lt;piecesAmount;i++){
                  g.drawImage(pic, 5, i*30, 30, 30, null);
              }
            }else{
                for(int i=0;i&lt;piecesAmount;i++){
                      g.drawImage(pic, 5, 300-(i*30), 30, 30, null);
                }  
            }
      }
            else{
        System.out.println("Slot Stack is empty Slot #"+slotNumber);
     }
  }
  
   }
  </code></pre>
  
  <p>and here is the eror i get: (i think it indicates the way i get the pic isnt good.)</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  at Try1.Slot.drawSlot(Slot.java:122)
  at Try1.Board.drawBoard(Board.java:128)
  at Try1.Board.resetBoard(Board.java:122)
  at Try1.GamePage.&lt;init&gt;(GamePage.java:98)
  at Try1.StartPage.startGame(StartPage.java:67)
  at Try1.StartPage$eventHandler.actionPerformed(StartPage.java:49)
  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.mouseReleased(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.dispatchEventImpl(Unknown Source)
  at java.awt.EventQueue.access$200(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$1.doIntersectionPrivilege(Unknown Source)
  at java.security.ProtectionDomain$1.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$1.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)
  </code></pre>
  
  <p>i would love to know what i did wrong.
  thanks you all i know its a long post and you really have to get into it 
  but i am a beginner and in need of help :).</p>