# Second ArrayList Won't Work

**URL:** https://discourse.processing.org/t/second-arraylist-wont-work/28711
**Category:** Coding Questions
**Tags:** homework
**Created:** [March 22, 2021, 3:08am UTC](https://discourse.processing.org/t/second-arraylist-wont-work/28711 "2021-03-22T03:08:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![spamelim](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@spamelim](https://discourse.processing.org/u/spamelim)
#### Post date: [March 22, 2021, 3:08am UTC](https://discourse.processing.org/t/second-arraylist-wont-work/28711/1 "2021-03-22T03:08:32Z")

</div>

I’m trying to make particles fall from wherever the mouse is clicked and each mousebutton displays a different type of particle. My main code for just the right mouse button works perfectly with rainbow particles. I added a second class and just changed it to all white particles to see if it would work and I get an error message. My code works on processing (the program) but on repl.it (with a plugin to read processing) it does not work. here’s my code:

```auto

List<Particle> particles;
List<Right> rights;

void setup()
{
  size(500, 500);
  particles = new ArrayList<Particle>();
  rights = new ArrayList<Right>();
 
}

void draw()
{
  background(20, 25, 50);
  fill(255);
  text(particles.size() + rights.size(),250,50);
  if (mousePressed && (mouseButton == LEFT)){
    particles.add(new Particle(mouseX,mouseY));
  }
  if(mousePressed && (mouseButton == RIGHT)){
    rights.add(new Right(mouseX,mouseY));
  }
  for(int i=0; i < particles.size(); i++){
    particles.get(i).display();
    particles.get(i).update();
    particles.get(i).delete();
  }
  for(int i=0; i < rights.size(); i++){
    rights.get(i).display();
    rights.get(i).update();
    rights.get(i).delete();
  }

  
}
class Right
{
	float x;
	float y;
  float grav;
  float ySpeed;
  float xSpeed;
  float r1;
  float g1;
  float b1;

	Right(float x, float y)
	{
		this.x = x;
		this.y = y;
    xSpeed = random(-1,1);
    ySpeed = 1;
    grav = 0.2;
    r1=random(255);
    g1=random(255);
    b1=random(255);
	}
	
  void update(){
   x+= xSpeed;
   y+= ySpeed;
   ySpeed+= grav;
  }

  void display(){
    fill(255,255,255);
    ellipse(x,y,5,5);
  }
 

  void delete(){
    if(y > height || x > width || x < 0 || y<0){
      rights.remove(this);
    }
  }
}

```

I left out the other particle class and it is named Right because I tried renaming it a couple times thinking that was the issue.

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [March 22, 2021, 8:48am UTC](https://discourse.processing.org/t/second-arraylist-wont-work/28711/2 "2021-03-22T08:48:53Z")

</div>

Hi,

Looks like you forgot few things in your code :

- the `import java.util.List;` in order to import the `List` class at the top of the program

- Where is the `Particle` class? With the code that you gave us, we can’t really run it 😉

Also note that on repl.it, some features might not work as expected compared to native Java Processing.

---

<div class="post-metadata">

### Author: ![spamelim](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@spamelim](https://discourse.processing.org/u/spamelim)
#### Post date: [March 22, 2021, 11:59am UTC](https://discourse.processing.org/t/second-arraylist-wont-work/28711/3 "2021-03-22T11:59:18Z")

</div>

The List class is basically the same as ArrayList in repl.it, when putting it into the processing IDE I change it to ArrayList, also here’s the particle class, it’s pretty much the same as the other class.

```auto
class Particle
{
	float x;
	float y;
  float grav;
  float ySpeed;
  float xSpeed;
  float r1;
  float g1;
  float b1;

	Particle(float x, float y)
	{
		this.x = x;
		this.y = y;
    xSpeed = random(-1,1);
    ySpeed = 1;
    grav = 0.2;
    r1=random(255);
    g1=random(255);
    b1=random(255);
	}
	
  void update(){
   x+= xSpeed;
   y+= ySpeed;
   ySpeed+= grav;
  }

  void display(){
    fill(r1,b1,g1);
    ellipse(x,y,5,5);
  }
 

  void delete(){
    if(y > height || x > width || x < 0 || y<0){
      particles.remove(this);
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![spamelim](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@spamelim](https://discourse.processing.org/u/spamelim)
#### Post date: [March 22, 2021, 12:15pm UTC](https://discourse.processing.org/t/second-arraylist-wont-work/28711/4 "2021-03-22T12:15:35Z")

</div>

Hey, thanks for your help, but I figured it out. Repl.it requires HTML code with all of your classes declared for anything to run, and I misspelled my class name in it. Thanks though.
