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.

are they in the same or in separate files?

are they in the same or in separate files?

They are in the same file.

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

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.

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.

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

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.