title: Raster Format Exception (Java)
body: <p>I'm trying to use some code like is seen on another questions answer: <a href="https://stackoverflow.com/a/621849/1044984">https://stackoverflow.com/a/621849/1044984</a></p>
  
  <p>Upon using this I get the following error:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.awt.image.RasterFormatException: (y + height) is outside of Raster
      at sun.awt.image.ByteInterleavedRaster.createWritableChild(Unknown Source)
      at java.awt.image.BufferedImage.getSubimage(Unknown Source)
      at main.Grid.paintComponent(Grid.java:111)
      at javax.swing.JComponent.paint(Unknown Source)
      at javax.swing.JComponent.paintChildren(Unknown Source)
      at javax.swing.JComponent.paint(Unknown Source)
      at javax.swing.JComponent.paintChildren(Unknown Source)
      at javax.swing.JComponent.paint(Unknown Source)
      at javax.swing.JLayeredPane.paint(Unknown Source)
      at javax.swing.JComponent.paintChildren(Unknown Source)
      at javax.swing.JComponent.paintToOffscreen(Unknown Source)
      at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
      at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
      at javax.swing.RepaintManager.paint(Unknown Source)
      at javax.swing.JComponent.paint(Unknown Source)
      at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
      at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
      at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
      at java.awt.Container.paint(Unknown Source)
      at java.awt.Window.paint(Unknown Source)
      at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
      at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
      at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
      at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$000(Unknown Source)
      at java.awt.EventQueue$1.run(Unknown Source)
      at java.awt.EventQueue$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$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>Here is the code relating to this error:</p>
  
  <pre><code>try {
  
              tileSheetBig = ImageIO.read(new File("sprites/tiles.png"));
              charSheetBig = ImageIO.read(new File("sprites/player.png"));
  
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          final int tileWidth = 64;
          final int tileHeight = 64;
          final int tileRows = 1;
          final int tileCols = 11;
          tileSheet = new BufferedImage[tileRows * tileCols];
  
          for (int i = 0; i &lt; tileRows; i++) {
              for (int j = 0; j &lt; tileCols; j++) {
                  tileSheet[(i * tileCols) + j] = tileSheetBig.getSubimage(i
                          * tileWidth, j * tileHeight, tileWidth, tileHeight);
              }
          }
  
          final int charWidth = 16;
          final int charHeight = 23;
          final int charRows = 2;
          final int charCols = 3;
          charSheet = new BufferedImage[charRows * charCols];
  
          for (int i = 0; i &lt; charRows; i++) {
              for (int j = 0; j &lt; charCols; j++) {
                  charSheet[(i * charCols) + j] = charSheetBig.getSubimage(i
                          * charWidth, j * charHeight, charWidth, charHeight);
              }
          }
  </code></pre>
  
  <p>Since not much was changed from the code provided on the answer I can not see what the issue may be. I've tried to google the error but not many answers out there relate to my issue.</p>