"Cannot make a static reference to the non-static method" Error
in
Programming Questions
•
6 months ago
Hello!
I'm getting an error message that read "Cannot make a static reference to the non-static method drawastar() from the type VanGoghFinalProject297D.astar." I'm not sure how to fix it.
The relevant code is below.
VanGoghFinalProject297D
int a, e, i, o, u, y;
PImage bckgrnd;
astar [] astars;
estar [] estars;
istar [] istars;
ostar [] ostars;
ustar [] ustars;
ystar [] ystars;
String[] lines;
void setup () {
size (400, 800);
bckgrnd = loadImage ("FinalProjectBackground.jpg");
image (bckgrnd, 0, 0);
a = 0;
e =0;
i =0;
u = 0;
y = 0;
lines = loadStrings("VanGoghLetter.txt");
for (int k = 0; k < lines.length; k++) {
String[] words = split(lines[k], ' ');
for (int i = 0; i< words.length; i++) {
for (int j = 0; j<words[i].length(); j++) {
char letters = words[i].charAt(j);
if (letters == 'a' || letters == 'A')
{
a++;
}
if (letters == 'e' || letters == 'E')
{
e++;
}
if (letters == 'i' || letters == 'I')
{
i++;
}
if (letters == 'o' || letters == 'O')
{
o++;
}
if (letters == 'u' || letters == 'U')
{
u++;
}
if (letters == 'y' || letters == 'Y')
{
y++;
}
}
}
}
int totala = a;
int totale = e;
int totali = i;
int totalo = o;
int totalu = u;
int totaly = y;
astar [] astars = new astar [a];
estar [] estars = new estar [e];
istar [] istars = new istar [i];
ostar [] ostars = new ostar [o];
ustar [] ustars = new ustar [u];
ystar [] ystars = new ystar [y];
}
void draw()
{
for (int i=0; i < a ; i++) {
astars[i] = new astar();
}
for (int i=0; i < e ; i++) {
estars[i] = new estar();
}
for (int j=0; j < i ; j++) {
istars[j] = new istar();
}
for (int i=0; i < o ; i++) {
ostars[i] = new ostar();
}
for (int i=0; i < u ; i++) {
ustars[i] = new ustar();
}
for (int i=0; i < y ; i++) {
ystars[i] = new ystar();
}
for (int i=0; i < a ; i++) {
astars[i] = astar.drawastar ();
}
for (int i=0; i < e ; i++) {
estars[i] = estar.drawastar ();
}
for (int j=0; j < i ; j++) {
istars[j] = istar.drawastar ();
}
for (int i=0; i < o ; i++) {
ostars[i] = ostar.drawastar ();
}
for (int i=0; i < u ; i++) {
ustars[i] = ustar.drawastar ();
}
for (int i=0; i < y ; i++) {
ystars[i] = ystar.drawastar ();
}
astar Class
class astar {
PImage astar = loadImage ("astar.gif");
float x = random (0, width);
float y = random (0, height);
float xconstrained;
float yconstrained;
astar() {
}
void drawastar ()
{
xconstrained = constrain (x, x/10, x-(x/10));
yconstrained = constrain (y, y/10, y-(y/10));
image (astar, xconstrained, yconstrained);
}
}
Thank you!
1