0

Hello I am getting following exception on line Stream grapes = ContentResolver.OpenInputStream(selectedImage); , the image is not null I am using it on my view so perhaps I referencing it wrong?

JavaLang Null pointer exception, attempt to invoke virtual method android.contentResolver on null object reference

public String ScanService()
        {
            var selectedImage = Android.Net.Uri.Parse("@Resources/drawable/portrait.png");
            Stream grapes = ContentResolver.OpenInputStream(selectedImage); 
            var options = new BitmapFactory.Options();
            options.InJustDecodeBounds = true;
            BitmapFactory.DecodeStream(grapes, null, options);
            string test = "test";
            
            Parsing(test);
            return test;
        }

I have tried this Android.Net.Uri.Parse("android.resource://demoregapp.android/drawable/portrait.png"); based on this

https://stackoverflow.com/questions/6602417/get-the-uri-of-an-image-stored-in-drawable

but still I am getting the same exception

brucaqs
  • 7
  • 6

1 Answers1

0

I don't see you use the Bitmap in your method.

If you want to create a bitmap from image in resource, you can use:

public String ScanService()
{
    //var selectedImage = Android.Net.Uri.Parse("@Resources/drawable/portrait.png");
    //Stream grapes = ContentResolver.OpenInputStream(selectedImage);
    //var options = new BitmapFactory.Options();
    //options.InJustDecodeBounds = true;
    //BitmapFactory.DecodeStream(grapes, null, options);

    BitmapFactory.DecodeResource(Resources, Resource.Drawable.portrait);

    string test = "test";            
    Parsing(test);
    return test;
}
nevermore
  • 15,432
  • 1
  • 12
  • 30