Android-Picasso java.lang.IllegalArgumentException: 目标不能为空。当图像视图处于警报对话框的自定义布局中时

Android-Picasso java.lang.IllegalArgumentException: Target must not be null. when the image view is in a custom layout for a alertdialog

我有java.lang.IllegalArgumentException: Target must not be null。当我尝试下载图像并将其放入 imageView By picasso 库时。让我向您展示我的代码:

public class ads_show extends AppCompatActivity {
private Toolbar toolbar;
private ImageView img_view1;
private HashMap<String, Object> hmap;
private ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ads_show);
    getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

   img = (ImageView) findViewById(R.id.ads_show_img);
    TextView title = (TextView) findViewById(R.id.title_ads_show);
    TextView desc = (TextView) findViewById(R.id.desc_ads_show);
    TextView seller = (TextView) findViewById(R.id.seller_ads_show);
    TextView phone = (TextView) findViewById(R.id.phone_ads_show);
    TextView email = (TextView) findViewById(R.id.mail_ads_show);
    TextView date = (TextView) findViewById(R.id.date_ads_show);

    Bundle ads = getIntent().getExtras();
    hmap = (HashMap<String, Object>) ads.get("ads");
    Picasso.with(this).load((String) hmap.get("image_path"))
            .resize(300, 150)
            .into(img);

    title.setText((String) hmap.get("title"));
    desc.setText((String) hmap.get("description"));
    seller.setText((String) hmap.get("seller"));
    phone.setText((String) hmap.get("phone"));
    email.setText((String) hmap.get("email"));
    date.setText((String) hmap.get("date"));


}


public void onFullScreenClick(View v) {

    try {



        LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(getApplicationContext().LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.fullscreen_image_show,null);
        img_view1 = (ImageView) findViewById(R.id.img_fullscreen);
        Picasso.with(this).load((String)hmap.get("image_path")).into(img_view1);
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setView(layout);
        alert.setCancelable(true);
        alert.setNeutralButton("exit", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        alert.show();
    } catch (Exception e) {
        Log.i("app_error", "Full screen" + e.toString());
    }

}

public void onBtnBackClick(View v) {
    finish();
}

}

我的问题是 onFullScreenClick 方法。 onCreate 方法中的图像视图工作正常。

您忘记绑定 ImageView 就像...

更改此行 ...

  img_view1 = (ImageView)layout.findViewById(R.id.img_fullscreen);