0

I am using last.fm API from here http://code.google.com/p/lastfm-java/

I downloaded it to my workspace, checked it as library, and imported it to my project... The problem comes when I try to use one method of the API

Artist[] artist = LastFmServer.searchForArtist("hatebreed");

I dont know why, it says

Cannot make a static reference to the non-static method searchForArtist(String) from the type LastFmServer

But I have another error trying to solve it. It causes this line

String artist = Artist.getName();

Cannot make a static reference to the non-static method getName() from the type Artist

its my first time using APIs, and i started getting tired of these errors, please help

BamsBamx
  • 4,139
  • 4
  • 38
  • 63

4 Answers4

1

Like other said you need to Instantiate LastFmServer like

LastFmServer mLastFmServer= new LastFmServer();

and then called you method like

Artist[] artist = mLastFmServer.searchForArtist("hatebreed");
Mohsin Naeem
  • 12,542
  • 3
  • 39
  • 53
  • if I do that i get "Cannot instantiate the type LastFmServer" error in your first line :( but this doesnt give any error: LastFmServer server = AndroidLastFmServerFactory.getServer(); – BamsBamx Aug 12 '12 at 17:00
  • I guess you are able to solve this problem http://stackoverflow.com/q/11924018/1436931..so now what is your problem? The main problem is, as also mentioned by others that you need to instantiate the `LastFmServer` with some `Default settings` – Mohsin Naeem Aug 12 '12 at 17:05
  • 1
    After solving the problem from link it seems that i got it working... Thanks – BamsBamx Aug 12 '12 at 17:24
0

You have to instantiate a LastFmServer and Artist with new (or the appropriate factory method.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
0

You need to instantiate the respective objects of LastFmServer and Artist by using new.

LastFmServer lastFmServerObj = new LastFmServer();
Swayam
  • 16,294
  • 14
  • 64
  • 102
0

You have to call the methods through a object and not make a static reference.

I'm guessing you'd create an LastFmServer like so (depending on the constructor).

LastFmServer object = new LastFmServer();

I hope this helps.

Luke Taylor
  • 9,481
  • 13
  • 41
  • 73