I had built an Android app a few months back, in which one fragment was used to display news using News API.
Recently, when I ran the app again, the following error is occurring.
I am attaching the code snippet where the error is occurring.
Ion.with(getActivity()).load("GET",urltemp).asJsonObject().setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
Log.d(TAG, "enter ");
String status = result.get("status").getAsString();
if (status.equals("ok")) {
JsonArray array = result.get("articles").getAsJsonArray();
for (int i = 0; i < array.size(); i++) {
JsonObject object = array.get(i).getAsJsonObject();
String author = object.get("author").toString();
String title = object.get("title").toString();
title = title.substring(1, title.length() - 1);
String url = object.get("url").toString();
url = url.substring(1, url.length() - 1);
String urlToImage = object.get("urlToImage").toString();
urlToImage = urlToImage.substring(1, urlToImage.length() - 1);
String date = object.get("publishedAt").toString();
String content = object.get("content").toString();
content = content.substring(1, content.length() - 1);
items.add(new ModelItems(title, author, date, urlToImage, url));
}
adapter = new SlideshowViewModel(getActivity(), items);
recyclerView.setAdapter(adapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
Log.d(TAG, "success");
} else {
Log.e(TAG, "error");
}
}
});
Now, I thought there could be two possible sources of error, either it is a problem with URL(urltemp variable) or it is with Ion library. Now, I pasted the URL in the browser, it is working fine. So, I guess the problem is with Ion. The JsonObject result is null always. Tried different things, but can't figure out any solution.
I have never used Postman. So, I am not aware of how to post API response. I am attaching how i assigned URL.
A thing I tried is pasting the above URL in the browser. When I paste the URL in browser, I get the following response: