What to do when the error "Non-static variable x cannot be referenced from static context" in Java. Lessons from the very first step in programming Remarks 01

Conclusion: Write "static" at the beginning of the method created separately from the main method.

For example, create a method with the method name abc int abc(int a,int b) If you get an error saying "Non-static variables cannot be referenced from a static context" when trying to compile static int abc(int a,int b) Just write "static" in the head and no error will occur.

My post, a memorandum of lessons learned from the very first steps in programming, It's like a learning record that a programming transcendental beginner left for himself.

I think that it is completely useless for people with high skills, but I hope that it will help those who have the same problem at the same level.

It may change suddenly because it is the first article posting.

Recommended Posts

What to do when the error "Non-static variable x cannot be referenced from static context" in Java. Lessons from the very first step in programming Remarks 01
[React.useRef] What to do when the latest state cannot be referenced in the event listener
[Programming beginner] What to do when rails s becomes an error in the local development environment
The first thing to do when you want to be happy with Heroku on GitHub with Eclipse in Java
[Ubuntu] What to do when MongoDB cannot be started due to a SocketException error
[Rails] What to do when rails db: migrate cannot be done because there is no table referenced by the foreign key
What to do when Git Repository cannot be displayed in Team Explorer for Eclipse in Azure
What to do if the adb command cannot be executed
[Rails] What to do when the error No database selected and Unknown database appears in db: migrate
[Ruby] What to do when the error "cannot load such file" appears when executing VS Code debug
Avoid the problem that session cannot be acquired when canary release when upgrading from Rails 4.2.x to 5.0.x
What to do about the "cannot be read or is not a valid ZIP file" error
What to do when the changes in the Servlet are not reflected
How to solve the unknown error when using slf4j in Java
What to do when CentOS cannot be started with VirtualBox on Catalina
What to do and how to install when an error occurs in DXRuby 1.4.7
What is CHECKSTYLE: OFF found in the Java source? Checkstyle to know from
What to do if the build fails with the error "Module compiled with Swift x.x.x cannot be imported by the Swift x.x.x compiler"
How to translate the error message into Japanese (What to do if you cannot log in for some reason)