# I have some problems with NPE, and i dont know how to fix it

**URL:** https://discourse.processing.org/t/i-have-some-problems-with-npe-and-i-dont-know-how-to-fix-it/26968
**Category:** Coding Questions
**Created:** [January 11, 2021, 11:12am UTC](https://discourse.processing.org/t/i-have-some-problems-with-npe-and-i-dont-know-how-to-fix-it/26968 "2021-01-11T11:12:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![deiwy](https://avatars.discourse-cdn.com/v4/letter/d/a9a28c/32.png) [@deiwy](https://discourse.processing.org/u/deiwy)
#### Post date: [January 11, 2021, 11:12am UTC](https://discourse.processing.org/t/i-have-some-problems-with-npe-and-i-dont-know-how-to-fix-it/26968/1 "2021-01-11T11:12:20Z")

</div>

i try to do a platformer, and i have problems with IntList  
main code:

```auto
block[] b;
button[] bu;
player p;

IntList yB = new IntList();
IntList xB = new IntList();

int menu = 0;

void setup(){
  
  for(int i = 0; i < levelone.length; i++){
    for(int j = 0; j < levelone.length; j++){
      if(levelone[j][i] == 1){
        xB.append(0);
        yB.append(0);
      }
    }
  }
  print(xB, yB);
  
  rectMode(CENTER);
  size(400, 400);
  
  p.takeMap();
  p = new player(50, 50, 30, 80, 1);
  bu = new button[2];
  b = new block[32];
  
  bu[0] = new button(200, 200, 100, 50, "Start", -1);
  bu[1] = new button(340, 40, 100, 50, "back", 1);
}
void draw(){
  if(menu == 0){
    background(#FF8A15);
  }else if(menu == 1){
    background(200);
  }
  if(menu == 0){
    bu[0].show();
    bu[0].pressed();
  }
  
  if(menu == 1){
    bu[1].show();
    bu[1].pressed();
    for(int i = 0; i < 8; i++){
      for(int j = 0; j < 8; j++){
        for(int a = 0; a < 16; a++){
          if(levelone[j][i] == 1){
            b[a] = new block(i*50, j*50, 50, 50, 100, 50, 50);
            b[a].show();
          } 
        }
      }
    }
    p.moveButtons(50);
    p.show();
    p.move();
    p.coll();
    p.fall();
  }
  
  
}

```

and class code:

```auto
class player{
  boolean pressed = false;
  
  float x, y, Width, Height, fallSpeed;
  float b1x = 35, b1y = 365, b2x = 365, b2y = 365, b3x = 90, b3y = 365;
  
  void takeMap(){
    for(int i = 0; i < yB.size(); i++){
      for(int j = 0; j < xB.size(); j++){
        if(levelone[j][i] == 1){
          xB.add(j,j*50);
          yB.add(i,i*50);
        }
      }
    }
  }
  
  boolean downColl(){
    for(int i = 0; i < yB.size(); i ++){
      if(y >= yB.get(i)){
        return true;
      }
    }
    
    return false;
  }
  
  boolean mouseInside1(){
    if(mouseX >= b1x - 25 && mouseX <= b1x + 25 && mouseY >= b1y - 25 && mouseY <= b1y + 25){
      return true;  
    }
    return false;
  }
  boolean mouseInside2(){
    if(mouseX >= b2x - 25 && mouseX <= b2x + 25 && mouseY >= b2y - 25 && mouseY <= b2y + 25){
      return true;  
    }
    return false;
  }
  boolean mouseInside3(){
    if(mouseX >= b3x - 25 && mouseX <= b3x + 25 && mouseY >= b3y - 25 && mouseY <= b3y + 25){
      return true;  
    }
    return false;
  }
  
  player(float X, float Y, float w, float h, float fS){
    x = X;
    y = Y;
    Width = w;
    Height = h;
    fallSpeed = fS;
  }
  
  void show(){
    rectMode(CENTER);
    fill(#0006FF);
    rect(x, y, Width, Height);
    noFill();
  }
  
  void hitbox(){
    
  }
  
  void fall(){
    y += fallSpeed;
  }
  
  void moveButtons(float size){
    fill(0);
    //left button
    if(mouseInside1() && mousePressed){
      x-=1;
    }
    rect(b1x, b1y, size, size);
    //right button
    if(mouseInside2() && mousePressed){
      x+=1;
    }
    rect(b2x, b2y, size, size);
    //up
    if(mouseInside3() && mousePressed){
      if(pressed == false){
        y-=70;
        pressed = true;
      }
    }
    if(downColl()){
      pressed = false;
    }
    rect(b3x, b3y, size, size);
    noFill();
  }
  
  void move(){
    
  }
  
  void coll(){
    if(downColl()){
      fallSpeed = 0;
    }else{
      fallSpeed = 1;
    }
    
  }
  
}

```

i dont know how to fix. Problem in `p.takeMap();`  
thanks in advance

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 11, 2021, 12:52pm UTC](https://discourse.processing.org/t/i-have-some-problems-with-npe-and-i-dont-know-how-to-fix-it/26968/2 "2021-01-11T12:52:14Z")

</div>

I don’t think you can use `yB.size()` as upper bound for the for loop. It might be bigger  
than ` levelone.length`
