Another basic newbie question..
I have been going over this for days now, Im sure it is very basic, but I have googled it over and over. I have java for dummies, school text book, and head first java, all of which have examples in them that almost look identical to this, but yet I still get an error.
The error is : non-static variable, this cannot be referenced from a static context.
Code:
package payrollwk4;
import java.util.Scanner;
/**
*
* @author erikjd21
*/
public class payrollwk4
{
public static void main(String[] args)
{
Employee empinfo = new Employee();// The error happens here
empinfo.getInfo();
}
public class Employee
{
Scanner input = new Scanner (System.in);
String name;
public void getInfo(){
System.out.println("Welcome to payroll manager!");
System.out.print("Please enter the employee's name:");
name = input.next();
}
}
}
This is the code that is giving the error. The part that is the error is where I am attempting to make an object of the employee class to use the method inside of it, to cause the information to print to the console. I feel that if I get this part down, the rest of the program will just flow together. Googling that error message says to create a constructor for the class to pull the method from. But I was under the impression that's what I was doing with the line that is giving me errors.
If anyone can, please tell me what I am forgetting to do.