簡體   English   中英

為什么我會出現這個錯誤?

[英]Why have I this error?

我正在從這里http://code.google.com/p/lastfm-java/使用last.fm API

我將其下載到我的工作區中,作為庫進行檢查,然后將其導入到我的項目中。當我嘗試使用一種API方法時,問題就來了

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

我不知道為什么,它說

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

但是我有另一個錯誤試圖解決它。 它導致這條線

String artist = Artist.getName();

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

這是我第一次使用API​​,我開始厭倦這些錯誤,請幫忙

就像其他人說的那樣,您需要Instantiate LastFmServer

LastFmServer mLastFmServer= new LastFmServer();

然后像這樣調用你的方法

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

您必須使用new (或適當的工廠方法)實例化LastFmServerArtist

您需要使用new 實例化 LastFmServerArtist的相應對象。

LastFmServer lastFmServerObj = new LastFmServer();

您必須通過對象調用方法,而不要進行靜態引用。

我猜你會像這樣創建LastFmServer (取決於構造函數)。

LastFmServer object = new LastFmServer();

我希望這有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM