# Why do i get NullPointerException and how to fix it

**URL:** https://discourse.processing.org/t/why-do-i-get-nullpointerexception-and-how-to-fix-it/4456
**Category:** Libraries
**Created:** [October 14, 2018, 11:59am UTC](https://discourse.processing.org/t/why-do-i-get-nullpointerexception-and-how-to-fix-it/4456 "2018-10-14T11:59:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![processing\_guy](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@processing\_guy](https://discourse.processing.org/u/processing_guy)
#### Post date: [October 14, 2018, 11:59am UTC](https://discourse.processing.org/t/why-do-i-get-nullpointerexception-and-how-to-fix-it/4456/1 "2018-10-14T11:59:18Z")

</div>

```auto
import fisica.*;

FBox boxButton;
FCircle circleButton;
FPoly polyButton;

FWorld world;

color buttonColor = #155AAD;
color hoverColor = #55AA11;
color bodyColor = #E6B800;
float pos = 0;
float angle = 0;  
float gx = 11;
float gy = 12;

void setup() {
  size(600, 600);
  smooth();

  Fisica.init(this);
  world.setGravity(gx, gy);
  world = new FWorld();
  world.setEdges();
  world.remove(world.left);
  world.remove(world.right);
  world.remove(world.top);
}

void draw() {
  rectMode(CENTER);
  fill(0);
  background(255);
  rect(pos, 0, 20, 60);
  pos = map(sin(angle), -1, 1, 40, 560);
  angle += 0.02;
  world.step();
  world.draw();
}

void mousePressed() {
  FBody pressed = world.getBody(mouseX, mouseY);
  if (pressed == boxButton) {
    FBox myBox = new FBox(60, 60);
    myBox.setPosition(pos, 25);
    myBox.setRotation(random(-0.2, 0.2));
    myBox.setVelocity(0, 100);
    myBox.setFillColor(bodyColor);
    myBox.setNoStroke();
    world.add(myBox);
  }
}

```

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [October 14, 2018, 4:51pm UTC](https://discourse.processing.org/t/why-do-i-get-nullpointerexception-and-how-to-fix-it/4456/2 "2018-10-14T16:51:49Z")

</div>

Which line is highlighted when you get the error?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [October 14, 2018, 5:14pm UTC](https://discourse.processing.org/t/why-do-i-get-nullpointerexception-and-how-to-fix-it/4456/3 "2018-10-14T17:14:28Z")

</div>

```auto
  world.setGravity(gx, gy);
  world = new FWorld();

```

possibly this 2 lines are out of order?

---

<div class="post-metadata">

### Author: ![processing\_guy](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@processing\_guy](https://discourse.processing.org/u/processing_guy)
#### Post date: [October 20, 2018, 12:52pm UTC](https://discourse.processing.org/t/why-do-i-get-nullpointerexception-and-how-to-fix-it/4456/4 "2018-10-20T12:52:10Z")

</div>

i already corrected the bug but thanks

---

<div class="post-metadata">

### Author: ![processing\_guy](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@processing\_guy](https://discourse.processing.org/u/processing_guy)
#### Post date: [October 20, 2018, 12:52pm UTC](https://discourse.processing.org/t/why-do-i-get-nullpointerexception-and-how-to-fix-it/4456/5 "2018-10-20T12:52:38Z")

</div>

i corrected the bug already but thanks
