We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Function get(int) does not exist... what?
Page Index Toggle Pages: 1
Function get(int) does not exist... what?? (Read 1913 times)
Function get(int) does not exist... what??
Jan 31st, 2010, 1:02pm
 
Hi guys
I'm having issues with the get() function inside an ArrayList. I've searched the forum and can't seem to find the solution for this problem...
When I run my project the compiler tells me that the get function doesn't exist.
Here's the code:

Code:

import processing.video.*;
import hypermedia.video.*;

// face detection
OpenCV opencv;
int faceDetected = 0;

int maxChar = 80;
int maxLines = 40;
ArrayList characters;

// MAIN

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

for (int i = 0; i < maxLines; i++) {
characters = new ArrayList();
characters.add(new Alphabet(i, maxChar, 100+i*3));
}

opencv = new OpenCV( this );
opencv.capture(width, height); // open video stream
opencv.cascade(OpenCV.CASCADE_FRONTALFACE_ALT); // load detection description
}

void draw() {
background(155);

for (int i = characters.size()-1; i>=0; i--) {
Alphabet characters = (Alphabet) characters.get(i);
characters.run();
}

// face detection
opencv.read();
Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 100, 100 );
noFill();
stroke(255,0,0);
for( int i=0; i<faces.length; i++ ) {
rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
if (faces[i].width > 0) {
faceDetected = 1;
}
}
}

void keyReleased () {
if (key == 'p') {
saveFrame("babel_01.tif");
}
}

public void stop() {
opencv.stop();
super.stop();
}
Re: Function get(int) does not exist... what??
Reply #1 - Jan 31st, 2010, 1:46pm
 
I see no reasons to get (sic) this error message!
But I see an issue: you have put characters = new ArrayList(); inside the loop, you probably want to put it before the loop. Otherwise, on each i, you overwrite the previous value of characters, hence the previously created Alphabet instance.
Re: Function get(int) does not exist... what??
Reply #2 - Feb 1st, 2010, 3:56am
 
Yeah, you were right about the placement of the new ArrayList() thing... i took it off the loop.

But it still doesn't work, I keep getting the same error message... I really can't imagine what might be happening.
In this project I'm working with two objects: the class Symbol, which creates the "characters" and the class Alphabet, which defines their behaviour. Symbols is loaded inside Alphabet as an ArrayList.
I thought maybe this could be a problem, so I decided to make a test. I copied and pasted Daniel Shiffman's ArrayListClass example from the Learning section into a new sketch and ran it in my computer. Ok, it worked. (sorry for not linking Shiffman's example, but the forum tells me I can't post links because I'm new here)
Then I decided to change the objects names to match the names in my project. I changed ONLY THE NAMES. Ran it. Got the same error: the function get(int) does not exist.

I'm gonna try to change the names in my sketch and post the results here. This is freaky.
Re: Function get(int) does not exist... what??
Reply #3 - Feb 1st, 2010, 4:58am
 
Quote:
Then I decided to change the objects names to match the names in my project. I changed ONLY THE NAMES.


I've had issues like that before too. Usually it's because I named my sketch the same as one of my classes. Make sure that your sketch, or any tabs used in your sketch, don't have the same name as any of your variables or classes, and try your code again.

This also explains why no one else will get the same error message - usually people just copy and paste posted code into a blank sketch to run it. And if they do save it, they probably won't name it the same thing you did!
Re: Function get(int) does not exist... what??
Reply #4 - Feb 1st, 2010, 4:59am
 
> I changed ONLY THE NAMES.

can you call characters something else in your code? i think i've seen this before and it may've been because i was using a reserved word as a variable name or it clashed with something defined elsewhere.

(there's no 'characters' in the reference, but you never know)

(ha ha, too slow)
Re: Function get(int) does not exist... what??
Reply #5 - Feb 1st, 2010, 6:13am
 
Hey, just found a solution to the problem

The thing is that many of the names I used for objects and variables, as koogy suggested, are similar - though not exactly equal - to Processing's own commands... so I changed everything that resembled those commands and it worked.
I changed maxChar, characters, Alphabet, all the names... and it worked.

So if anyone has the same issue just try different names!

Thanks guys!
Re: Function get(int) does not exist... what??
Reply #6 - Feb 4th, 2010, 1:30am
 
That seems like a strange solution to me - I don't see why similar names would be an issue. There must be something else that caused the problem, but I can't see what it would be. Is this a bug?
Re: Function get(int) does not exist... what??
Reply #7 - Feb 4th, 2010, 2:18am
 
you have two objects called characters, one is from the Alphabet class, the other is an ArrayList. So this is a naming issue, but you are not overwriting any of Processing methods.

This works:

Code:

 for (int i = characters.size()-1; i>=0; i--) {
   Alphabet alphabet = (Alphabet) characters.get(i);
   alphabet.run();
 }

Page Index Toggle Pages: 1