Indrek Kõue
Indrek Kõue

Reputation: 6449

Creating MvxImageView programatically and attaching URI to ImageUrl returns NullPointerException

I have custom view which extends Android.Support.V4.View.ViewPager and has one property List<Uri> _productImages; As soon as _productImages is set through MvxBind and not null, I create an adapter (which extends PagerAdapter) and attach it to my custom ViewPager.

In my adapter:

public override Java.Lang.Object InstantiateItem (ViewGroup p0, int p1){

  MvxImageView view = new MvxImageView (Context, null);
  view.ImageUrl = Images [p1].AbsoluteUri;

  view.LayoutParameters = new ViewGroup.LayoutParams (ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent);

  return view;
}

Line with view.ImageUrl = Images [p1].AbsoluteUri; returns NullPointerException (view.ImageUrl is null). As we can see in MvxImageView _imageHelper seems to be the problem source. But how can it be null when i'm creating MvxImageView with constructor public MvxImageView(Context context, IAttributeSet attrs): base(context, attrs) which initialises _imageHelper ?

Upvotes: 0

Views: 544

Answers (1)

Stuart
Stuart

Reputation: 66882

The constructor for MvxImageView can trace a warning - see https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Droid/Views/MvxImageView.cs

Are you loading the download cache and file plugins? (And json if required) For some more info, see:

Upvotes: 1

Related Questions