static vs. non-static

I am having the hardest time getting this to work.  I keep getting that "non-static method cannot be referenced from a static context" error, and I've tried creating an object to call it, but that isn't working either (it gets rid of the above error, but doesn't work for what I want to do)

so I created this class that doesn't say "static" anywhere in it:

package semantic.shum;

import java.awt.event.*;
import java.util.*;
import java.io.*;

public class find3 {
   
 public void find3(WindowEvent e) {
     semantic.shum.Semantic.tool_dummy_button.doClick();
 }

}

but i still get the "cannot be referenced from a static context" error.  What makes the above code a "static context"?  How do I make it non-static?
swp3h6Asked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
0
 
CEHJCommented:
Buttons and their events seldom exist in a static context, so doClick is probably *not* static
0
 
swp3h6Author Commented:
"Buttons and their events seldom exist in a static context, so doClick is probably *not* static"
none of this should be static...

but the line:
semantic.shum.Semantic.tool_dummy_button.doClick();

still gets the error:

non-static variable tool_dummy_button cannot be referenced from a static context.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
CEHJCommented:
That's because 'tool_dummy_button' is an *instance* variable of semantic.shum.Semantic, not a class (static) one
0
 
AstaedusConnect With a Mentor Commented:
new semantic.shum.Semantic.tool_dummy_button().doClick();
this works because here you make an instance of the class semantic.shum.Semantic.tool_dummy_button

semantic.shum.Semantic.tool_dummy_button is the name of a class.
only static methods can be used with a class.
If you want to use other methods you need a reference to an instance of that class.

It's basic java:
you're trying to do this:
MyClass.doSomething();
when you need:
MyClass myInstance;
myInstance = new MyClass();
myInstance.doSomething();

The only way you can do MyClass.doSomething(); is by making the doSomething method static.
0
 
objectsConnect With a Mentor Commented:
try:

public class find3 {
     
 public void find3(WindowEvent e) {
     new semantic.shum.Semantic().tool_dummy_button.doClick();
 }

}

or instead of creating an instance each time, make it a member var:

public class find3 {
      private semantic.shum.Semantic() semantic = new semantic.shum.Semantic();

 public void find3(WindowEvent e) {
     semantic.tool_dummy_button.doClick();
 }

}

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.