Hi all,
Im new to java.

I get this error.
Non-static variable this cannot be referenced from a static context
myClass c=new myClass()
^

this is my code

public class MyOwnBm{
private Hashtable myHash=new Hashtable();


public static void main(String[] args)
{
 myClass c=new myClass();
	c.match();
}



public class myClass{....}

}

PLZ... help me I've wasted hours on this.

Re: Non-static variable this cannot be refred from a static contet 80 80

are they in the same or in separate files?

Re: Non-static variable this cannot be refred from a static contet 80 80

are they in the same or in separate files?

They are in the same file.

Re: Non-static variable this cannot be refred from a static contet 80 80

If you don't need an inner class, make MyClass static.

Re: Non-static variable this cannot be refred from a static contet 80 80

your code is full of errors.
try creating MyClass (or myClass, if you prefer) in a separate java file, and since you call a match method on it, make sure that method exists.

Re: Non-static variable this cannot be refred from a static contet 80 80

You declared MyClass inside MyOwnBM, and you didn't declare it static, so it's just like any other instance member - you can't refer to it without an instance of the MyOwnBM class. See
http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
Unless MyClass needs direct access to instance variables from MyOwnBM, just declare it static, or declare it outside MyOwnBM.

Re: Non-static variable this cannot be refred from a static contet 80 80

You declared MyClass inside MyOwnBM, and you didn't declare it static, so it's just like any other instance member - you can't refer to it without an instance of the MyOwnBM class. See
http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
Unless MyClass needs direct access to instance variables from MyOwnBM, just declare it static, or declare it outside MyOwnBM.

thank you. i made it static

Re: Non-static variable this cannot be refred from a static contet 80 80

OK! Please mark this "solved" for future reference. Thanks J.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.