# Do you know why there is an error?

**URL:** <https://discourse.processing.org/t/do-you-know-why-there-is-an-error/37301>\
**Category:** Coding Questions\
**Created:** [June 3, 2022, 1:12pm UTC](https://discourse.processing.org/t/do-you-know-why-there-is-an-error/37301 "2022-06-03T13:12:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ell](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@ell](https://discourse.processing.org/u/ell)\
**Post date:** [June 3, 2022, 1:12pm UTC](https://discourse.processing.org/t/do-you-know-why-there-is-an-error/37301/1 "2022-06-03T13:12:23Z")

</div>

Hello genius!  
I’m a beginner and I need your help.  
Why is there an error in the first line of this code?

int s\_num = 40;

PShape s;  
PShape b;

Virus Virus1 = new Virus[s\_num];  
Cell Cells= new Cell[40];

void setup()  
{  
size(800,600,P3D);

```
s = loadShape("Virus.obj");
b = loadShape("cell.obj");
s.scale(3.0);
 b.scale(20.0);

```

for(int i =0; i\< s\_num; i++){  
Virus1[i] = new Virus();  
}

for(int i=0; i\< 1; i++){  
Cells[i] = new Cell ();  
}

}

void draw()  
{  
background(0);  
for(int i =0; i \< s\_num; i++){  
Virus1[i].display();  
Virus1[i].move();  
}  
for(int i =0; i \< 1; i++){  
Cells[i].display();  
Cells[i].move();  
}

}  
class Virus{

float xpos,ypos,zpos,speed,w;

Virus()  
{  
xpos = random(width);  
ypos = random(height);  
zpos = random(-200,-400);  
speed = random(3,5);  
//w = random(1.800);

```
  }

```

void display()  
{  
noStroke();  
fill(#ffcc33);  
pushMatrix();  
translate(xpos,ypos,zpos);  
shape(s,w,w);  
popMatrix();  
}

void move(){  
zpos += speed;  
if(zpos \> 500 ){  
zpos = -200;  
}

}

}

class Cell{  
float xpos,ypos,zpos,speed,w;

Cell()  
{  
xpos = mouseX;  
ypos = mouseY;  
zpos = mouseX;  
speed = 5;  
w = 0;  
}

void display()  
{  
noStroke();  
fill(255,5,188);  
pushMatrix();  
translate(xpos,ypos,zpos);  
shape(b,w,w);  
popMatrix();  
}

void move()  
{  
xpos = mouseX;  
ypos = mouseY;  
}

}

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [June 3, 2022, 1:29pm UTC](https://discourse.processing.org/t/do-you-know-why-there-is-an-error/37301/2 "2022-06-03T13:29:53Z")

</div>

Easy fix mate, you have to declare the virus and cell arrays with

```auto
Virus[] Virus1 = new Virus[s_num];
Cell[] Cells = new Cell[40];

```

Note the after the Virus and Cell type, you put it after the naming of them objects

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [June 3, 2022, 1:34pm UTC](https://discourse.processing.org/t/do-you-know-why-there-is-an-error/37301/3 "2022-06-03T13:34:03Z")

</div>

On second try, seems you can put it there, not sure then

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [June 3, 2022, 1:37pm UTC](https://discourse.processing.org/t/do-you-know-why-there-is-an-error/37301/4 "2022-06-03T13:37:12Z")

</div>

I substituted a cube and sphere in and it works on my pc, can you post the error code?, it could be the 3d obj file you’re trying to import

---

<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:** [June 3, 2022, 1:42pm UTC](https://discourse.processing.org/t/do-you-know-why-there-is-an-error/37301/5 "2022-06-03T13:42:33Z")

</div>

this runs with text()

I also had to add the brackets `[]`

```auto

int s_num = 40;

PShape s;
PShape b;

Virus[] viruses = new Virus[s_num];
Cell[] cells= new Cell[40];

void setup() {
  size(800, 600, P3D);

  s = loadShape("Virus.obj");
  b = loadShape("cell.obj");
  //s.scale(3.0);
  //b.scale(20.0);

  for (int i =0; i< s_num; i++) {
    viruses[i] = new Virus();
  }

  for (int i=0; i< 40; i++) {
    cells[i] = new Cell ();
  }
}

void draw()
{
  background(0);
  for (int i =0; i < s_num; i++) {
    viruses[i].display();
    viruses[i].move();
  }
  for (int i =0; i < 40; i++) {
    cells[i].display();
    cells[i].move();
  }
}

// =====================================================================================

class Virus {

  float xpos, ypos, zpos, speed, w;

  Virus()
  {
    xpos = random(width);
    ypos = random(height);
    zpos = random(-200, -400);
    speed = random(3, 5);
    //w = random(1.800);
  }

  void display()
  {
    noStroke();
    fill(#ffcc33);
    pushMatrix();
    translate(xpos, ypos, zpos);
    shape(s, w, w);
    text("V", 0, 0); 
    popMatrix();
  }

  void move() {
    zpos += speed;
    if (zpos > 500 ) {
      zpos = -200;
    }
  }
}

// =====================================================================================

class Cell {
  float xpos, ypos, zpos, speed, w;

  Cell()
  {
    xpos = mouseX;
    ypos = mouseY;
    zpos = mouseX;
    speed = 5;
    w = 0;
  }

  void display()
  {
    noStroke();
    fill(255, 5, 188);
    pushMatrix();
    translate(xpos, ypos, zpos);
    shape(b, w, w);
    text("C", 0, 0); 
    popMatrix();
  }

  void move()
  {
    xpos = mouseX;
    ypos = mouseY;
  }
}
// =====================================================================================

```

---

<div class="post-metadata">

**Author:** ![ell](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@ell](https://discourse.processing.org/u/ell)\
**Post date:** [June 3, 2022, 3:07pm UTC](https://discourse.processing.org/t/do-you-know-why-there-is-an-error/37301/6 "2022-06-03T15:07:24Z")

</div>

Thank you very much for your sincerity. Thanks to you, I solved it well!!!

---

<div class="post-metadata">

**Author:** ![ell](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@ell](https://discourse.processing.org/u/ell)\
**Post date:** [June 4, 2022, 5:46am UTC](https://discourse.processing.org/t/do-you-know-why-there-is-an-error/37301/7 "2022-06-04T05:46:33Z")

</div>

Thank you so much! It worked out well!!
