[BUG] -Getting File Not Found Exception when creating new File with cropped uri.getPath()
See original GitHub issue- Lib Version 2.2.1
Describe the bug
I am able to crop the image and put in ImageView successfully.
But when I am using the same URI path to create a file it’s throwing FileNotFoundException
.
The URI path is starting like content://..something/package name/ myfiles/...
something like this.
When I debugged I am able to see some data like NO CACHE inside the URI value.
I am pasting my code below: Calling Method to crop:
public void onSelectImageClick() {
CropImage
.activity(null)
.setOutputCompressFormat(Bitmap.CompressFormat.JPEG)
.setGuidelines(CropImageView.Guidelines.ON)
.setFixAspectRatio(true)
.start(this);
}
Getting cropped result in onActivityResuly()
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
Glide.with(this)
.load(result.getUri())
.into(actorPic);
isImageViewAdded = true;
//handleCropResult(CropImage.getActivityResult(data))
imagePath = result.getUri();
//imagePath = CropImage.getPickImageResultUri(this, data);
//insertSingleItem(result.getUri());
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Toast.makeText(this, "Cropping failed: " + result.getError(), Toast.LENGTH_LONG).show();
}
}
if(requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE){
Uri imageUri = CropImage.getPickImageResultUri(AddActorsActivity.this, data);
imagePath = imageUri;
}
}
But the imageview is able to find the path and successfully update the cropped image inside it through Glide.
Expected behavior I think the cropped Image is not caching and so it’s happening like this.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
getting FileNotFoundException when passed content uri as ...
Seems like the problem in destination URI. I've used the code from sample: SampleActivity:233 to create destinationUri : val destinationUri = ...
Read more >File not found exception (Path from URI) - java - Stack Overflow
This gives a file not found exception for the path format is the reason ... getPath(getContext(),uri)); options = new BitmapFactory.
Read more >Uri | Android Developers
Creates a Uri from a file. The URI has the form "file:// ". Encodes path characters with the exception of '/'. Example: "file:///tmp/android.txt" ......
Read more >File (Java SE 11 & JDK 11 ) - Oracle Help Center
Creates a new File instance by converting the given file: URI into an abstract ... pathname if and only if a file with...
Read more >FileNotFoundException.getName() to return missing file name
When I catch a java.io.FileNotFoundException, it would be nice to get the file name. As it stands, the detail message from ...
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
Hi, In my case I solved the problem following this: https://developer.android.com/training/data-storage/shared/documents-files?hl=es-419
Hope it helps you too! Regards,
Please try the latest
3.0.0
release and let me know