Explore Courses Blog Tutorials Interview Questions
0 votes
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
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.4k questions

32.5k answers


108k users

Browse Categories