# Having trouble with ArrayList cant find an answer

**URL:** <https://discourse.processing.org/t/having-trouble-with-arraylist-cant-find-an-answer/11546>\
**Category:** Beginners\
**Created:** [May 24, 2019, 12:32pm UTC](https://discourse.processing.org/t/having-trouble-with-arraylist-cant-find-an-answer/11546 "2019-05-24T12:32:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BL4K](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@BL4K](https://discourse.processing.org/u/BL4K)\
**Post date:** [May 24, 2019, 12:32pm UTC](https://discourse.processing.org/t/having-trouble-with-arraylist-cant-find-an-answer/11546/1 "2019-05-24T12:32:41Z")

</div>

I am getting "The function hits() does not expect parameters

```

for (int i=bullet.size()-1;i>0;i--){
    b.display();
    b.update(); 
    for (int j=asteroid.size()-1;j>0;j--){
      if(bullet.get(i).hits(asteroid.get(i)))){ 

      }//end bullet.hits(asteroid) loop
    }//end for loop
}

```

The function in my bullet class;

```

void hits(){
      float d = dist(pos.x,pos.y,a.pos.x,a.pos.y);
      if( d<a.r){
        print("hit");
      }

```

---

<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:** [May 24, 2019, 1:11pm UTC](https://discourse.processing.org/t/having-trouble-with-arraylist-cant-find-an-answer/11546/2 "2019-05-24T13:11:21Z")

</div>

> [@BL4K](#):
>
> …hits(asteroid.get(i))

and

> [@BL4K](#):
>
> hits(){

does not fit!  
you should pass the asteroids parameter.

---

<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:** [May 24, 2019, 1:13pm UTC](https://discourse.processing.org/t/having-trouble-with-arraylist-cant-find-an-answer/11546/3 "2019-05-24T13:13:17Z")

</div>

void hits(){

must be

void hits(Bullet a){

Within the brackets you define the parameters

---

<div class="post-metadata">

**Author:** ![BL4K](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@BL4K](https://discourse.processing.org/u/BL4K)\
**Post date:** [May 24, 2019, 1:34pm UTC](https://discourse.processing.org/t/having-trouble-with-arraylist-cant-find-an-answer/11546/4 "2019-05-24T13:34:30Z")

</div>

so if (asteroids.get(i)) is an ArrayList of PVectors and this is written globally, I have written the hits() in the bullet class and checking the distance between the bullet.x and bullet.y to the asteroid.x and asteroid.y.

If I add void hits(PVector pos){ which would be the bullet pvector in the class, i then get hits() expecting paramenters hits(PVector) but its an array of PVectors

---

<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:** [May 24, 2019, 2:02pm UTC](https://discourse.processing.org/t/having-trouble-with-arraylist-cant-find-an-answer/11546/5 "2019-05-24T14:02:53Z")

</div>

> [@BL4K](#):
>
> bullet.get(i).hits(asteroid.get(i)))){

We are talking about this line

Depending on what asteroids contains,  
In void hits say PVector or Bullet as parameter

---

<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:** [May 24, 2019, 2:03pm UTC](https://discourse.processing.org/t/having-trouble-with-arraylist-cant-find-an-answer/11546/6 "2019-05-24T14:03:07Z")

</div>

Parameters must match

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 26, 2019, 2:23pm UTC](https://discourse.processing.org/t/having-trouble-with-arraylist-cant-find-an-answer/11546/7 "2019-05-26T14:23:16Z")

</div>

To summarize: here is a function:

```auto
void hi(){
  println("hi");
}

```

Based on the empty () in its fist line, it does not expect parameters. You can call it like this:  
`hi();`  
…but not like this:  
`hi("hello");`

Here is another function:

```auto
void word(String wrd){
  println(wrd);
}

```

It does expect parameters – the parameter `wrd` that appears in the () in the first line. You can call it like this:  
`word("hello");`  
…but not like this:  
`word();`
