0

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.

Edited by coroll: n/a

4
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by JamesCherrill
0

are they in the same or in separate files?

They are in the same file.

0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.