图片未在 android 工作室中与 Picasso 一起显示

Images not displaying with Picasso in android studio

使用 Picasso 显示从网络上截取的多张图片 API,但是在 20 张图片中只显示了一张。这是内存或缓存问题吗?我在应用程序的其他地方使用了相同的代码,它工作得很好。我确定这也可能是一个循环,但正如我所说,该代码已在应用程序的其他地方运行。

 protected void onPostExecute(String nowplaying) {

        if (nowplaying == null) {
            nowplaying = "THERE WAS AN ERROR";
        }

        try {


            JSONObject object = (JSONObject) new JSONTokener(nowplaying).nextValue();
            JSONArray all_results = object.getJSONArray("results");

            String ImageURL = "https://image.tmdb.org/t/p/w500";


            ImageURL += (all_results.getJSONObject(0).getString("poster_path"));
            TestName1.append(all_results.getJSONObject(0).getString("title"));

            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster1);

            ImageURL += (all_results.getJSONObject(1).getString("poster_path"));
            TestName2.append(all_results.getJSONObject(1).getString("title"));

            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster2);

            ImageURL += (all_results.getJSONObject(2).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster3);

            ImageURL += (all_results.getJSONObject(3).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster4);

            ImageURL += (all_results.getJSONObject(4).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster5);

            ImageURL += (all_results.getJSONObject(5).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster6);

            ImageURL += (all_results.getJSONObject(6).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster7);

            ImageURL += (all_results.getJSONObject(7).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster8);

            ImageURL += (all_results.getJSONObject(8).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster9);

            ImageURL += (all_results.getJSONObject(9).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster10);

            ImageURL += (all_results.getJSONObject(10).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster11);

            ImageURL += (all_results.getJSONObject(11).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster12);

            ImageURL += (all_results.getJSONObject(12).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster13);

            ImageURL += (all_results.getJSONObject(13).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster14);
            ImageURL += (all_results.getJSONObject(14).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster15);

            ImageURL += (all_results.getJSONObject(15).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster16);

            ImageURL += (all_results.getJSONObject(16).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster17);

            ImageURL += (all_results.getJSONObject(17).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster18);

            ImageURL += (all_results.getJSONObject(18).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster19);

            ImageURL += (all_results.getJSONObject(19).getString("poster_path"));
            Picasso.with(getApplicationContext()).load(ImageURL).into(BookTicketsFilmPoster20); 



        } catch (JSONException e) {
            e.printStackTrace();
        }



    }

适配器Class:

URL url = null;
url = GenerateMovieThumbnailsURL.buildURL(list.get(count).getMoviePosterPath());     
Picasso.with(mContext).load(url.toString()).into(viewHolder.mMovieItem);

URL 创作者 Class:

public class GenerateMovieThumbnailsURL {
  final static String BASE_MOVIE_THUMBNAIL_URL = "https://image.tmdb.org/t/p/";

  final static String imageQuality = "w185";
  String imageURL;

  GenerateMovieThumbnailsURL(String imageExtendedURI) {
    imageURL = imageExtendedURI;
  }

public static URL buildURL(String imageLink) {

    Uri builtURI = Uri.parse(BASE_MOVIE_THUMBNAIL_URL).buildUpon()
            .appendPath(imageQuality)
            .appendEncodedPath(imageLink)
            .build();


    URL url = null;
    try {
        url = new URL(builtURI.toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    return url;

  }
}

提取图像缩略图路径:

JSONArray jsonArray = jsonObject.getJSONArray("results");


                for (int i = 0; i < jsonArray.length(); i++) {

                    JSONObject js = jsonArray.getJSONObject(i);
                    MovieItem item = new MovieItem();
                    item.setMovieTitle(js.getString("poster_path"));
                    list.add(item);}
ImageURL1 = ImageURL + (all_results.getJSONObject(0).getString("poster_path"));                
TestName1.append(all_results.getJSONObject(0).getString("title"));

Picasso.with(getApplicationContext()).load(ImageURL1).into(BookTicketsFilmPoster1);   

ImageURL1 = ImageURL + (all_results.getJSONObject(1).getString("poster_path"));

TestName2.append(all_results.getJSONObject(1).getString("title"));



Picasso.with(getApplicationContext()).load(ImageURL1).into(BookTicketsFilmPoster2);