• Post Reply Bookmark Topic Watch Topic
  • New Topic

Non-Static method cannot be referenced from a static context?  RSS feed

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code:

and my theOutput(); method in my main says Non-Static method cannot be referenced from a static context. Is there any way to get around this or fix this error?
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lexi Turgeon wrote:
and my theOutput(); method in my main says Non-Static method cannot be referenced from a static context. Is there any way to get around this or fix this error?


In order to call a method (that is not static), you need to use an instance. In your code, you forgot to create the instance.

Henry
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did not forget, just do not know how to. Any tips on that?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lexi Turgeon wrote:Did not forget, just do not know how to. Any tips on that?


The Oracle tutorial on creating objects may be a good place to start...

https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html

Henry
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lexi Turgeon wrote:Did not forget, just do not know how to. Any tips on that?

Come now, Lexi, that's not true. See this thread: https://coderanch.com/t/673290/java/run-code-main-class

You have been using the new keyword for a while now.
 
Sheriff
Posts: 4293
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This link will help you create a main method in a way that avoids the problem.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!