【发布时间】:2017-08-13 13:59:42
【问题描述】:
我正在尝试学习如何使用 Spotify API,但他们的 sample code 不起作用。
我使用的是 Netbeans 8.1,我确实导入了 .jar 文件,它在 Api api = Api.builder() 行中显示 java.lang.NoClassDefFoundError: net/sf/json/JSON。
import com.wrapper.spotify.Api;
import com.wrapper.spotify.methods.AlbumRequest;
import com.wrapper.spotify.models.Album;
import java.util.List;
public static void main(String[] args) {
// Create an API instance. The default instance connects to https://api.spotify.com/.
Api api = Api.builder()
.clientId("<secret>")
.clientSecret("<secret>")
.redirectURI("<secret>")
.build();
// Create a request object for the type of request you want to make
AlbumRequest request = api.getAlbum("7e0ij2fpWaxOEHv5fUYZjd").build();
// Retrieve an album
try {
Album album = request.get();
// Print the genres of the album
List<String> genres = album.getGenres();
for (String genre : genres) {
System.out.println(genre);
}
} catch (Exception e) {
System.out.println("Could not get albums.");
}
}
【问题讨论】:
-
我的回答有帮助吗? stackoverflow.com/help/someone-answers
-
@user7294900 实际上,在我了解更多有关 maven 的信息后,我可以看到问题所在,但确实有帮助。