-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.lang.NullPointerException: uri #535
Comments
I'm having this same issue, but the file doesn't already exist. Other than that it's identical except for the file type being PDF. It worked fine before, even if the file existed. Then it saved the file as Device: OnePlus 7 Por
PS: |
Same as |
Duplicate of #548 |
Getting a null pointer exception from ContentResolver.openAssetFileDescriptor method. I can reproduce this problem with certain files most of times.
I was running the app on SamSung S9 Plus.
at com.android.internal.util.Preconditions.checkNotNull(Preconditions.java:133)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1484)
at android.content.ContentResolver.openOutputStream(ContentResolver.java:1234)
at vn.hunghd.flutterdownloader.DownloadWorker.downloadFile(DownloadWorker.java:358)
at vn.hunghd.flutterdownloader.DownloadWorker.doWork(DownloadWorker.java:208)
addFileToDownloadsApi29 method seems to return a valid uri; however, openOutputStream(uriApi29, "w") method at DownloadWorker.java:358 is causing this problem.[Updated] I found that ContentResolver.insert fails because the same file already exists. I called File.exists before creating a new DownloadTask, but it didn't find the same file. So I added the code below to check for the same file before inserting a new row.
// Check if the same file already exists
String strId = "";
String[] projection = {"_id", "_display_name"};
Cursor cursor = contentResolver.query(
collection,
projection,
null,
null,
null);
if (cursor.moveToFirst()) {
do {
strId = cursor.getString(cursor.getColumnIndex("_id"));
String displayName = cursor.getString(cursor.getColumnIndex("_display_name"));
log("[" + strId + "] " + displayName);
if (displayName.equals(filename)) {
log("Same file found.");
Uri uri = Uri.parse(collection.toString() +
File.separator + strId);
return uri;
}
} while (cursor.moveToNext());
cursor.close();
}
outputStream = context.getContentResolver().openOutputStream(uriApi29, "w");
I can access to the image with the HTTP Url with no problem.
Here is the log:
I/System.out(14329): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(14329): (HTTPLog)-Static: isSBSettingEnabled false
D/DownloadWorker(14329): Content-Type = image/png
D/DownloadWorker(14329): Content-Length = 906615
D/DownloadWorker(14329): Charset = null
D/DownloadWorker(14329): fileName = Pursue Spray .png
D/DownloadWorker(14329): Update notification: {notificationId: 33, title: Pursue Spray .png, status: 4, progress: -1}
W/System.err(14329): java.lang.NullPointerException: uri
W/System.err(14329): at com.android.internal.util.Preconditions.checkNotNull(Preconditions.java:133)
W/System.err(14329): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1484)
W/System.err(14329): at android.content.ContentResolver.openOutputStream(ContentResolver.java:1234)
W/System.err(14329): at vn.hunghd.flutterdownloader.DownloadWorker.downloadFile(DownloadWorker.java:358)
W/System.err(14329): at vn.hunghd.flutterdownloader.DownloadWorker.doWork(DownloadWorker.java:208)
W/System.err(14329): at androidx.work.Worker$1.run(Worker.java:85)
W/System.err(14329): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err(14329): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err(14329): at java.lang.Thread.run(Thread.java:919)
I/WM-WorkerWrapper(14329): Worker result FAILURE for Work [ id=543e7685-40e8-4b7d-9848-cd27f6399210, tags={ flutter_download_task, vn.hunghd.flutterdownloader.DownloadWorker } ]
D/ConnectivityManager(14329): unregisterNetworkCallback; CallingUid : 10918, CallingPid : 14329
The text was updated successfully, but these errors were encountered: