I am writing an android project using themoviedatabase api (tmdb). I use this to get data from tmdb https://github.com/UweTrottmann/tmdb-java
And I use this library to set image to ImageView https://github.com/square/picasso
But when i run, it return null error at Picasso.get().load()
java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.uwetrottmann.tmdb2.entities.BaseMovie.backdrop_path' on a null object reference
@Override
public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
bindingView(view);
bindingAction(view);
// Create an instance of the service you wish to use
// you should re-use these
Tmdb tmdb = new Tmdb(API_KEY);
MoviesService moviesService = tmdb.moviesService();
// 438148 Minions
// 299537 Captain Marvel
//616037 Thor 4
movie = loadMovieData(438148, tmdb, moviesService);
Picasso.get().load("https://image.tmdb.org/t/p/original"+movie.backdrop_path).into(poster);
}
public Movie loadMovieData(int movieId, Tmdb tmdb, MoviesService moviesService) {
try {
Response<Movie> response = moviesService
.summary(movieId, "en")
.execute();
if (response.isSuccessful()) {
Movie movie = response.body();
return movie;
}
} catch (Exception e) {
// see execute() javadoc
e.printStackTrace();
return null;
}
return null;
}