How to call getClass() from a static method in Java?
I have a class that must have some static methods. Inside these static methods I need to call the method getClass() to make the following call: public static void startMusic() { URL songPath = getClass().getClassLoader().getResource("background.midi"); } However Eclipse tells me: Cannot make a static reference to the non-static method getClass() from the type Object What is the appropriate way to fix this compile time error? Just use TheClassName.class instead of getClass() . Sergey Ushakov As for the code example in the question, the standard solution is to reference the class explicitly by