ImageView is null while inflating other activity dialog in View MVC

25 Views Asked by At

I am getting null in image ImageView Object while getting activity_dialog. the context is activity in ReadActivityMVCView based on MVC pattern, Any idea how to fix this?

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference

  public ReadActivityMVCView(LayoutInflater inflator, ViewGroup parent,Activity readActivity) {
        activity = readActivity;
        rootView = inflator.inflate(R.layout.activity_read_main, parent, false);
        setRootView(rootView);
}
  private void loadPhoto(Bitmap bitmap) {
        LayoutInflater inflater = this.activity.getLayoutInflater();
        this.activity.getWindow().addContentView(inflater.inflate(R.layout.activity_dialog, null),
                new ViewGroup.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT));
        ImageView image = rootView.findViewById(R.id.fullimage);
        if (bitmap != null) {
            image.setImageBitmap(bitmap);
        }

SOLVED USING THE BELOW CODE

 LayoutInflater inflater = activity.getLayoutInflater();
        View dialogView = inflater.inflate(R.layout.activity_dialog, null);
        this.activity.getWindow().addContentView(dialogView,
                new ViewGroup.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT));
        ImageView image = dialogView.findViewById(R.id.fullimage);
        if (bitmap != null) {
            image.setImageBitmap(bitmap);
        }
0

There are 0 best solutions below