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)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With