Reputation: 2831
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)
Upvotes: 2
Views: 577
Reputation: 144
As I see it, you have declared an array
of Salesperson
objects and you want to put data into it from a file. What you are missing is the new
keyword. Using new
keyword creates a new object of the class and calls the constuctor
in the process. You may use the follwing code:
array[k] = new Salesperson(infile.nextInt(), infile.nextInt(), myName);
Upvotes: 2
Reputation: 194
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.
Upvotes: 2
Reputation: 6359
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.
Upvotes: 11