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 issueI 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:
- Created 3 years ago
- Comments:9
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same problem here😭
Any updates on this?