I use the code below to get JSON
data (img, name), and everything works fine, but I get a lot of report in Google Console under ANRs & Crashes :
java.lang.NullPointerException:
at maa.app.Fragments.fragmentAnime$3.onSuccess (fragmentAnime.java:75)
at maa.app.Fragments.fragmentAnime$6.a (fragmentAnime.java:52)
at maa.app.Fragments.fragmentAnime$6.onResponse (fragmentAnime.java:2)
at com.android.volley.request.StringRequest.c (StringRequest.java:4)
at com.android.volley.request.StringRequest.a (StringRequest.java:2)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run (ExecutorDelivery.java:30)
at android.os.Handler.handleCallback (Handler.java:789)
at android.os.Handler.dispatchMessage (Handler.java:98)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6942)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
myApplication :
public class MApplication extends MultiDexApplication {
public static RequestQueue requestQueue;
@Override
public void onCreate() {
super.onCreate();
requestQueue = Volley.newRequestQueue(getApplicationContext());
}
Fragment :
StringRequest stringRequest = new StringRequest(Request.Method.GET,
URL_DATA,
s -> {
List<Post> listItems = new ArrayList<>();
try {
JSONObject jsonObject = new JSONObject(s);
JSONArray array = jsonObject.getJSONArray("bgs");
for (int i = 0; i < array.length(); i++) {
JSONObject o = array.getJSONObject(i);
Post item = new Post(
o.optString("img"),
o.optString("name")
);
listItems.add(item);
}
callback.onSuccess(listItems);
} catch (JSONException e) {
slowInternetConnection();
}
},
callback::onError) {
};
if (getActivity() != null && isAdded()) {
stringRequest.setShouldCache(false);
requestQueue.getCache().clear();
requestQueue.add(stringRequest);
}
can anyone help me to get resolve this issue?