# Type mismatch: cannot convert from element type Object to filename.pde

**URL:** <https://discourse.processing.org/t/type-mismatch-cannot-convert-from-element-type-object-to-filename-pde/45046>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [September 14, 2024, 12:01pm UTC](https://discourse.processing.org/t/type-mismatch-cannot-convert-from-element-type-object-to-filename-pde/45046 "2024-09-14T12:01:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nedireact](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@nedireact](https://discourse.processing.org/u/nedireact)\
**Post date:** [September 14, 2024, 12:01pm UTC](https://discourse.processing.org/t/type-mismatch-cannot-convert-from-element-type-object-to-filename-pde/45046/1 "2024-09-14T12:01:46Z")

</div>

```auto
float time = 0.0;
void draw() {
  for (Particle p : particles) {
 
    // love/hate vector
    float lovex = 0.0;
    float lovey = 0.0;
 
    for (Particle o : particles) {
      // do not compare with yourself
      if (p.id != o.id) {
        // calculate vector to get distance and direction
        PVector v = new PVector(o.x-p.x, o.y-p.y);
        float distance = v.mag();
        float angle = v.heading();
 
        // love!
        float love = 1.0 / distance;
        // or hate...
        if (distance<2.0) love = -love;
 
        // mood factor
        love *= p.moodSimilarity(o);
        // not too fast!
        love *= 0.5;
 
        // update love vector
        lovex += love * cos(angle);
        lovey += love * sin(angle);
      } 
 
      // calculated love vector will be our speed in resultant direction
      p.dx = lovex;
      p.dy = lovey;
    }
  }
 
  // update and draw
  for (Particle p : particles) {
    p.update();
    p.draw();
  }

```

 ![WX20240914-200131@2x](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/9/b/9bd9c53d624d2a4b92619cd4d5652b123f37852d.png)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 14, 2024, 12:06pm UTC](https://discourse.processing.org/t/type-mismatch-cannot-convert-from-element-type-object-to-filename-pde/45046/2 "2024-09-14T12:06:58Z")

</div>

How have you declared the global variable _particles_?  
It’s important to define the datatype of the items a container stores (generics):

> **[ArrayList / Reference](https://processing.org/reference/arraylist)**
>
> An ArrayList stores a variable number of objects. This is similar to making an array of objects, but with an ArrayList, items can be easily added and removed from the ArrayList and it is…

---

<div class="post-metadata">

**Author:** ![nedireact](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@nedireact](https://discourse.processing.org/u/nedireact)\
**Post date:** [September 14, 2024, 12:21pm UTC](https://discourse.processing.org/t/type-mismatch-cannot-convert-from-element-type-object-to-filename-pde/45046/4 "2024-09-14T12:21:16Z")

</div>

WOW, Thanks for your help! I realized what the problem was and I could fix the code error.  
by the way, I’m a rookie just learning to program！ 😀 😀
