Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I'm using Processing 3.0.2, and I'm trying to run a function I defined in a class from an ArrayList. Processing says "The function dis() does not exist." when it obviously does.

What I have tried:

I have an ArrayList called "cs," and it contains "Circle" objects. "Circle" is a class that I made which contains a function called "dis()," and it displays the circle. I have an outside function called "discs()" (display circles) that has a for loop that's supposed to display each circle in the list. Here's what I have:

Java
int cam_x;
int cam_y;
int mp = 0;
ArrayList cs;

void setup() {
  size(500, 500);
  cs = new ArrayList<Circle>();
}

void draw() {
  if (mousePressed && mp < 1) {
    cs.add(new Circle(mouseX,mouseY));
    mp = 1;
  } else if (!mousePressed) {
    mp = 0;
  }
  discs();
}

class Circle {
  int xa;
  int ya;
  Circle(int x,int y) {
    xa = x;
    ya = y;
  }
  
  void dis() {
    ellipseMode(CENTER);
    fill(255,0,0);
    noStroke();
    ellipse(xa, ya, 25, 25);
  }
}

void discs() {
  for (int i = 0;i<=cs.size();i++) {
    cs.get(i).dis();
  }
}


The variables cam_x/y are unused right now.
Posted
Updated 31-Aug-18 10:34am

1 solution

I think you need to make a cast here for cs in your function discs().

This link might help you or point you in the right direction.
java - Cannot Find Method of an Object in ArrayList - Stack Overflow[^]
 
Share this answer
 
Comments
Member 13968996 31-Aug-18 17:15pm    
It worked! Thanks for the help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900