Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - symbol not found (constructor)

So I'm writing some code that reads from a file:

array[k] = Salesperson(infile.nextInt(), infile.nextInt(), myName);

I wrote a constructor for Salesperson that looks somewhat likes this:

public Salesperson(int cheese, int butter, String name)

When I try to compile (first Salesperson, then the actual program), I get this:

program.java:39: cannot find symbol

symbol : method Salesperson(int,int,java.lang.String)

like image 537
tew Avatar asked Dec 18 '25 19:12

tew


2 Answers

You're missing the new keyword. e.g.

array[k] = new Salesperson(infile.nextInt(), infile.nextInt(), myName);

This is resulting in the compiler attempting to find a method called Salesperson that returns a type of Salesperson, which would be invalid anyway.

like image 182
Jeff Watkins Avatar answered Dec 20 '25 11:12

Jeff Watkins


Use the new keyword. You should do it:

array[k] = new Salesperson(infile.nextInt(), infile.nextInt(), myName);

You can't assign without the new keyword because it's not a method where you can return a value.

like image 40
andremw Avatar answered Dec 20 '25 11:12

andremw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!