Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (2.6k points)

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?

1 Answer

0 votes
by (46k points)
Simply try TheClassName.class instead of getClass().

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...