First of all, Scanner
objects doesn't hava a method called nexlinet
, I guess you want nextLine()
instead.
About the error, you can't reference a non-static
variable from a static
method (in this case, that method is main
).
Why? Because static
variables can be used even if no instances of the class have been created.
How to solve it?
You can declare the variable getin
as static
:
static Scanner getin = new Scanner(System.in);
Or you can create an instance of the class and access to the instance field getin
:
Initials some_name = new Initials();
// ...
name = t.getin.nextLine();
Notes:
- Try to follow Java naming conventions. Use
'mixedCase'
for methods/variables and use 'CamelCase'
for classes/interfaces.
- I'd recommend you to read about access modifiers. Why? Look at the second solving way. The class
Initials
should provide a getter/setter method for the instance field getin
, so you don't have full access on it. Also, it's a good practice to declare instance fields as private
(and use getters/setters).