# Problems with converting a P5.js sketch to Processing

**URL:** <https://discourse.processing.org/t/problems-with-converting-a-p5-js-sketch-to-processing/30963>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [June 29, 2021, 12:10pm UTC](https://discourse.processing.org/t/problems-with-converting-a-p5-js-sketch-to-processing/30963 "2021-06-29T12:10:09Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![lmato](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@lmato](https://discourse.processing.org/u/lmato)\
**Post date:** [June 29, 2021, 1:58pm UTC](https://discourse.processing.org/t/problems-with-converting-a-p5-js-sketch-to-processing/30963/3 "2021-06-29T13:58:17Z")

</div>

Hi, after reading some documentation I reached this stage but I’m getting an error

```auto

// A Mover object
Mover mover;

void setup() {
  size(640,360);
  mover = new Mover(); 
}

void draw() {
  background(0);
  
  // Update the location
  mover.update();
  // Display the Mover
  mover.display(); 
}

```

```auto
class Mover {

  // The Mover tracks location, velocity, and acceleration 
  PVector location;
  PVector velocity;
  PVector acceleration;
  // The Mover's maximum speed
  Particles[] particle = new Particles[10];
  float topspeed;
  int e;

  Mover() {
    // Start in the center
    location = new PVector(width/2,height/2);
    velocity = new PVector(0,0);
    topspeed = 5;
    
    for(e = 0; e<9; e++){
      particle[e] = new Particles();
  }}

  void update() {
    
    // Compute a vector that points from location to mouse
    PVector mouse = new PVector(mouseX,mouseY);
    PVector acceleration = PVector.sub(mouse,location);
    // Set magnitude of acceleration
    acceleration.setMag(0.2);
    
    // Velocity changes according to acceleration
    velocity.add(acceleration);
    // Limit the velocity by topspeed
    velocity.limit(topspeed);
    // Location changes by velocity
    location.add(velocity);
  }

  void display() {
    fill(255);
    ellipse(location.x, location.y, 4, 4);
    for(int i = 9; i>0; i -=1){
      particle[i].x = particle[i-1].x;
      particle[i].y = particle[i-1].y;
    }
    particle[0].x = location.x;
    particle[0].y = location.y;
  }
}

```

```auto
class Particles {
  float x,y;
  
  Particles() {
    init();
  }
  void init(){
    x = 0;
    y = 0;
  }
}

```

I get nuller pointer exception in line

```auto
   particle[i].x = particle[i-1].x;

```

This code is to generate the particle (the head and tail).

Gonna keep trying

I found the problem, in

```auto
    for(e = 0; e<9; e++){
      particle[e] = new Particles();
  }

```

Had to change the 9 for the list length and that’s it 🙂 !

---

_[View the full topic](https://discourse.processing.org/t/problems-with-converting-a-p5-js-sketch-to-processing/30963)._
