Getting "Target must not be null." exception when using Picasso component

SashaRoyzenSashaRoyzen USUniversity

Anyone here ever used ITarget with Picasso. I'm getting: Java.Lang.IllegalArgumentException: Target must not be null. Here is my code:

private void GetBitmap(string imageUrl)
    {
        if (string.IsNullOrWhiteSpace(imageUrl))
            return null;

        var target = new Target();

        Picasso.With(View.Context).Load(imageUrl)
            .Into(target);
    }

    private class Target : ITarget
    {
        public void Dispose()
        {
    //some code
        }

        public IntPtr Handle { get; }
        public void OnBitmapFailed(Drawable p0)
        {
    //some code
        }

        public void OnBitmapLoaded(Bitmap p0, Picasso.LoadedFrom p1)
        {
    //some code
        }

        public void OnPrepareLoad(Drawable p0)
        {
    //some code
        }
    }

Answers

  • You need to derive from Java.Lang.Object.

    private class LoaderTarget : Java.Lang.Object, ITarget
    { 
        public void OnBitmapFailed(Drawable p0)
        {
    
        }
    
        public void OnBitmapLoaded(Bitmap p0, Picasso.LoadedFrom p1)
        {
    
        }
    
        public void OnPrepareLoad(Drawable p0)
        {
    
        }
    }
    
  • HungTXHungTX USMember

    @JoshuaMartin.3993 That's right, many thanks.

Sign In or Register to comment.