question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetFileDescriptor android.content.ContentResolver.openAssetFileDescriptor(android.net.Uri, java.lang.String)' on a null object reference

See original GitHub issue

I am getting the following exception:

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:354)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
       at java.util.concurrent.FutureTask.run(FutureTask.java:271)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:764)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetFileDescriptor android.content.ContentResolver.openAssetFileDescriptor(android.net.Uri, java.lang.String)' on a null object reference
       at android.provider.ContactsContract$Contacts.openContactPhotoInputStream(ContactsContract.java:2142)
       at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.loadContactPhotoHighRes(ContactsServicePlugin.java:647)
       at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.access$700(ContactsServicePlugin.java:54)
       at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:434)
       at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:405)
       at android.os.AsyncTask$2.call(AsyncTask.java:333)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:764)

Following the stack tree it seems that the problem occurs in the frameworks/base/core/java/android/provider/ContactsContract.java when the content resolver is null

                try {
                    AssetFileDescriptor fd = cr.openAssetFileDescriptor(displayPhotoUri, "r");
                    if (fd != null) {
                        return fd.createInputStream();
                    }
                } catch (IOException e) {
                    // fallback to the thumbnail code
                }

Looking at the plug-in code there is one place on the onDetachedFromEngine method where this is set to null:

  @Override
  public void onDetachedFromEngine(FlutterPluginBinding binding) {
    methodChannel.setMethodCallHandler(null);
    methodChannel = null;
    contentResolver = null;
    this.delegate = null;
  }

I am getting crash reports for this problem but I cannot simply reproduced them in my app. My best guess is that it might be related with the running the getContacts call in the background and then closing the app.

Is this a known issue? Anyone else having the same problem?

Thanks for the support

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
em-azharcommented, Feb 15, 2021

Same problem here😭

0reactions
DVendycommented, Nov 29, 2022

Any updates on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upload image error: Attempt to invoke virtual method 'java ...
The problem is that your Uri does not get the image as it should so you need to create your own Uri for...
Read more >
AssetManager - Android Developers
String, int) : Attempt to load contents into memory, for fast small reads. ... an uncompressed asset by mmapping it and returning an...
Read more >
core/java/android/content/ContentResolver.java - Google Git
{@link ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}. */. public static final String SYNC_EXTRAS_UPLOAD ...
Read more >
ContentResolver Class (Android.Content) | Microsoft Learn
This class provides applications access to the content model. ... This is the Android platform's base MIME type for a content: URI containing...
Read more >
android.content.Context.getContentResolver java ... - Tabnine
public String getRealPathFromURI(Context context, Uri contentUri) { Cursor cursor = null; try { String[] proj = { MediaStore.Images.Media.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found