user151841
user151841

Reputation: 18046

Trouble with constructor in the Processing Java environment

I am new to Java and working in the Processing environment. I want to create a class that has a few objects in it, but I am getting an error when I try to construct those classes' object.

The bzaVertex is supposed to be an object within the bza object, but when I seemingly try to construct it, Processing says "The constructor sketch.BzaVertext(int) is undefined." I don't understand how Bza is getting its constructor called properly, but not the child object -- I seem to be calling them the same way?

I have this code all in the main class. I'm using Processing 2.0b7. What am I doing wrong?

Bza bza;
void setup() {
  bza = new Bza();
}

public class BzaVertex {
  public void BzaVertex(int d) {
  }
}

public class Bza {
  BzaVertex v1; 

  public void Bza() {
    v1 = new BzaVertex(4);
  }
}

Upvotes: 0

Views: 594

Answers (1)

Will Jamieson
Will Jamieson

Reputation: 926

constructors do not have a return type so you need to to remove the void from both of them

class BzaVertex {
    public BzaVertex(int d) {
    }
}

class Bza {
    BzaVertex v1; 

    public Bza() {
        v1 = new BzaVertex(4);
    }
    }

    public class Main
    {
    public static void main(String[] args) 
    {
        Bza bza;
        bza = new Bza();
    }
     }  

that should solve the error

Upvotes: 3

Related Questions