We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I keep getting an error message that my constructor does not exist, but I'm not sure what I've done wrong. I've asked a couple of friends, and none of them can find the error either. Help?
Heart heartx;
void setup()
{
size (500, 500);
smooth();
background(0);
noStroke();
heartx = new Heart(color(0,0,150), 50, 15, -5, 90, 5, 40, 10);
}
void draw()
{
background(255);
heartx.display();
}
class Heart
{
color co;
float a;
float b;
float c;
float d;
float e;
float f;
float g;
Heart(color tempco, float tempa, float tempb, float tempc, float tempd, float tempe, float tempf, float tempg)
{
co = tempco;
a = tempa;
b = tempb;
c = tempc;
d = tempd;
e = tempe;
f = tempf;
g = tempg;
}
void display()
{
smooth();
noStroke();
fill(c);
beginShape();
vertex(a, b);
bezierVertex(a, c, d, e, a, f);
vertex(a, b);
bezierVertex(a, c, g, e, a, f);
endShape();
}
}
Answers
The only possible issue I see is that the constructor specifies floats and the new Heart(...) uses integers. You could try specifying the numbers as 50.0, 15.0 etc.
Just a guess...
Seems to run just fine for me. I would suggest using an array instead of several temporary floats though
Thank you for the help, guys! Changing the ints to floats didn't fix it, and if it's working for you, I think at this point it might just be my ide malfunctioning. I'm going to try downloading it again. Thanks!
it runs for me too
weird...
I have edited your original post so the code lines are numbered.
This is wrong because a float variable will accept integers e.g.
float f = 10; // is just fine
I only mention this because newbies might think this can cause problems and it can't.
BTW your code worked for me but if you still have problems try this -
Using your code I suggest that you change the data type
color
toint
so line 20 becomesint co;
and line 30 becomes
Heart(int tempco, float tempa, float tempb, float tempc, float tempd, float tempe, float tempf, float tempg) {
Do not change line 9
Processing uses the data type
color
as a pseudonym forint
and Processing will replacecolor
forint
where it is being used to represent a data type.In line 9 you have
color(0, 0, 150)
In this case we are calling a function called
color
we know this because the word is followed by a(
I believe i had the same problem as you. My code run perfectly on one instance and gave that error on the other. I found that happened because the name of the .pde file was exactly the same as the name of the class i was using. Hope that helps you or anyone who stumble upon this topic.
I had struggled w/ this glitch a few times in the past too! X_X
We gotta watch out the name we give to save the sketch doesn't coincide w/ any class/interface names! :-\"
I hate to bring up an old post, but It came up at the top of the search results and somebody might still find this useful. Any answer to this?....
EDIT nevermind, I wasn't passing the right variable type into my constructor, which was giving me the error
thread is from sept 2015...
also you are VERY wrong about the capital c in class.
http://www.wideskills.com/java-tutorial/java-classes-and-objects