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.

[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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
TomasMVazquezcommented, Mar 11, 2021

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,

0reactions
Canatocommented, Apr 13, 2021

Please try the latest 3.0.0 release and let me know

Read more comments on GitHub >

github_iconTop 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 >

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