Debug上的Java.lang.NullPointerException?

时间:2014-11-29 14:17:46

标签: java eclipse

这是我的项目代码:

public void render(int[] pixels, int offset, int row) {
      for (int yTile = yOffset <<3; yTile <= (yOffset + height) >>3; yTile++) {
       int yMin = yTile * 8 - yOffset;
       int yMax = yMin + 8;
       if (yMin < 0) yMin = 0;
       if (yMax > height) yMax = height;

       for (int xTile = xOffset <<3; xTile <= (xOffset + width) >>3; xTile++) {
        int xMin = xTile * 8 - xOffset;
        int xMax = xMin + 8;
        if (xMin < 0) xMin = 0;
        if (xMax > width) xMax = width;

        int tileIndex = (xTile &(MAP_WIDTH_MASK)) + (yTile &(MAP_WIDTH_MASK)) * MAP_WIDTH;

        for (int y = yMin; y <yMax; y++) {
         int sheetPixel = ((y + yOffset) & 7) * sheet.width + ((xMin + xOffset) & 7);
         int tilePixel = offset + xMin + y * row;
         for (int x = xMin; x < xMax; x++) {
          int colour = tileIndex * 4 + sheet.pixels[sheetPixel++];
          pixels[tilePixel++] = colours[colour];
         }
        }
      }
     }
 }
}

当我运行我的项目时,它在这一行上给我一个错误:

int colour = tileIndex * 4 + sheet.pixels[sheetPixel++];

您能否告诉我如何解决此错误?

1 个答案:

答案 0 :(得分:0)

在您的代码中,我没有看到sheet的定义位置。 尝试改变它

int colour = tileIndex * 4 + pixels[sheetPixel++];

我假设您正在尝试访问int[] pixels中作为函数调用中的参数传递的值。