kaaes / spotify-web-api-android

A wrapper for Spotify Web API. It uses Retrofit to create Java interfaces from API endpoints
http://kaaes.github.io/spotify-web-api-android
MIT License
379 stars 139 forks source link

Images of tracks in getAlbumTracks return null. #148

Closed kulkulkul closed 7 years ago

kulkulkul commented 7 years ago

Hi.

SpotifyService.getAlbumTracks(albumId, new Callback<Pager<Track>>() {
                 @Override
                  public void success(Pager<Track> trackPager, Response response) {
                  }

                 @Override
                  public void failure(RetrofitError error) {

                 }
});

In case "success" method of getAlbumTracks(), trackPager.items don't have album's image. example, Log.d("albumurl",trackPager.items.get(0).album.images.get(0).url) When i write source above and run myapp, a nullpointerexception occurs like this.

FATAL EXCEPTION: main
Process: com.demo.musicplayer, PID: 2232
 java.lang.NullPointerException: Attempt to read from field 'java.util.List kaaes.spotify.webapi.android.models.AlbumSimple.images' on a null object reference
at com.demo.musicplayer.SearchActivity$8$1$1.success(SearchActivity.java:413)
at com.demo.musicplayer.SearchActivity$8$1$1.success(SearchActivity.java:409)
at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
MathewLloyd commented 7 years ago

Hi

This is not an issue. The getAlbumTracks method is using the Spotify Web API endpoint of GET /albums/{id}/tracks. When looking at the endpoint guide, we can see that this returns the tracks simplified model which does not contain an album attribute, therefore there is no image to be located. The current getAlbumTracks method is using a Track model when it should instead be using the TrackSimple model.

If you require the album image, I suggest using the getAlbum method which uses the API endpoint of GET /albums/{id} Using, the input of the album id as you had previously, but instead returns a full Album model which contains a TrackSimple model for each track in the album.