0

I am creating a memory game but it doesn't open the pictures. I have seen similar questions but they aren't helpful to my problem. Here is the error

List<Photo> photos =new ArrayList<>();  
@BindView(R.id.txt_player_one) TextView playerOneTextView;
@BindView(R.id.txt_player_two) TextView playerTwoTextView;

The part with JSON : JsonObjectRequest photoRequest = new JsonObjectRequest (Request.Method.GET, uriBuilder.toString(), null, new Response.Listener() {

                @Override
                public void onResponse(JSONObject response) {
                    photos = PhotoJsonUtils.extractPhotos(response);
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                }
            });

The code that shows Image:

private void showImage(ImageView img, int card) {

        if (cardsArray[card] == 101) {
            Picasso.with(this).load(photos.get(0).getImgUrl()).into(img);
        } else if (cardsArray[card] == 102) {
            Picasso.with(this).load(photos.get(1).getImgUrl()).into(img);
        } else if (cardsArray[card] == 103)
Era Kuqi
  • 1
  • 3
  • have you checked to see if `response` actually has anything? It seems like `PhotoJsonUtils.extractPhotos(response)` is returning null thus your `photos` list is null. – avalerio Oct 12 '21 at 02:37

1 Answers1

0

First check whether you are successfully recieving the response through this request .If your json response is only an array (array of objects or array of simple data types) then you can try for JsonArrayRequest otherwise if your json response is complex consisting of array and other data (fusion of array of objects and other data items) then unpack the json response sequentially using keys to get your required data correctly.

Preetam Pal
  • 256
  • 2
  • 7