#"Cannot make static reference in non-static method", even though all involved components are static

20 messages ยท Page 1 of 1 (latest)

stoic fjord
#

Hi, I am getting the following error by eclipse, when I try to call the method "wait" from the class "Action": Cannot make a static reference to the non-static method wait(long) from the type Object (Relevant code attached)
The wait method used to be part of the Main class itself and i'm trying to change that. By creating the Action class, I have different utility functions like this one. To avoid having to call Action.wait() every time, I used a static import.

When I comment out the original wait() from Main, it tells me the above. I am confused, considering, that my wait() method takes an int and not a long. Does somebody know what I might be missing?

loud oxideBOT
#

โŒ› This post has been reserved for your question.

Hey @stoic fjord! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

frigid dock
#

Please clarify... If you run the code as is right now, what is the error?

#

I suspect that its trying to call the method wait() in the Object class ๐Ÿค”
That might be taking priority above the static import

stoic fjord
stoic fjord
sacred blaze
#

Name it differently

frigid dock
#

No I don't. The only thing I can think of is rename the method

#

Yep or dont use static import

stoic fjord
#

If not using static import, what would be an appropriate way to do it?

sacred blaze
#

Action.wait(3000);

stoic fjord
#

alright, no way around it apparently. Thanks for the advice

loud oxideBOT
sacred blaze
#

Though fundamentally it's just bad practice to reuse an existing name

stoic fjord
#

Is there an existing wait method I can override? I just don't wanna call Thread.sleep() in a try catch clause all the time

sacred blaze
#

No, because it doesn't sleep. But you could name your method sleep

stoic fjord
#

And then use static import?

sacred blaze
#

sure

stoic fjord
#

Alright, thank you ๐Ÿ‘