my problem is, that I always get a nullpointerexception in my retrofit request, but I have no idea why...
Feed
is a own created class which should contain the response from the retrofit request.
ServiceAPI:
@GET("top-headlines?country=de&apiKey=xxx")
Call<Feed> getNewsFeed();
Retrofit-Call in onCreateView
:
Retrofit retrofitNewsData = new Retrofit.Builder()
.baseUrl(NetworkService.NEWS_DATA_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
Log.d(TAG, "network service connected to: " + retrofitNewsData);
ServiceRepository serviceRepositoryNewsData = retrofitNewsData.create(ServiceRepository.class);
Call<Feed> callNews = serviceRepositoryNewsData.getNewsFeed();
callNews.enqueue(new Callback<Feed>() {
@Override
public void onResponse(Call<Feed> call, Response<Feed> response) {
newsFeed = response.body();
Log.d(TAG, "Habe den feed: " + newsFeed + " erhalten." + response.code());
}
@Override
public void onFailure(Call<Feed> call, Throwable t) {
}
});`
Base-URL:
public static final String NEWS_DATA_BASE_URL = "https://newsapi.org/v2/";