user3128274
user3128274

Reputation: 13

actual and formal argument lists differ in length, but they actually are the same

So I am trying to create a boxclient to make a box out of points with the following file:

import java.awt.Point;

public class boxclient{

    public static void main(String[] args){
     Point o = new Point(5,5);
     Point t = new Point(5,5);
     Point r = new Point(5,5);
     Point f = new Point(5,5);

     Box one = new Box(o,t,r,f);
     }

    }

That was my client, and this is my box class:

import java.awt.Point;


public class Box{
private int x,y;
private int rot;
private int width, height;

private Point[] my = new Point[4];
private Box[] conto = new Box[100];
private int concount = 0;

 public void Box(Point topleft, Point topright, Point botleft, Point botright){
  this.my[0] = topleft;
  this.my[1] = topright;
  this.my[2] = botleft;
  this.my[3] = botright;
  }

And I am getting this error for no apparent reason:

1 error found: File: C:\Users\George\Desktop\2dShooter\boxclient.java [line: 11] Error: constructor Box in class Box cannot be applied to given types; required: no arguments found: java.awt.Point,java.awt.Point,java.awt.Point,java.awt.Point reason: actual and formal argument lists differ in length

Any ideas? I've tried restarting my drjava and saving and compiling and rewriting as the same name a few times.

Upvotes: 1

Views: 1075

Answers (3)

dhamibirendra
dhamibirendra

Reputation: 3046

You need to add a constructor. You are here only calling a method.

Upvotes: 0

Keerthivasan
Keerthivasan

Reputation: 12880

You have got confused with Constructor and Method. Methods have return types atleast void. But Constructors don't have any return type. They just create the new instance.

So,

public void Box(Point topleft, Point topright, Point botleft, Point botright){

denotes a Method declaration, it will not be recognized as a Constructor. that's why the error is thrown.

You have to declare the Constructor with No return type, just like the one below

public Box(Point topleft, Point topright, Point botleft, Point botright){

Now, the Constructor has the correct argument list of Point type. There will not be any error now. Hope you understand!

Upvotes: 1

tckmn
tckmn

Reputation: 59273

public void Box(Point topleft, Point topright, Point botleft, Point botright){

That is not the correct way to declare a constructor. Replace that with:

public Box(Point topleft, Point topright, Point botleft, Point botright){

Upvotes: 7

Related Questions