CanHub / Android-Image-Cropper

Image Cropping Library for Android, optimised for Camera / Gallery.
Apache License 2.0
1.26k stars 260 forks source link

[BUG] - DialogFragment usage of CropImageView leads to crash #116

Closed omkar-tenkale closed 3 years ago

omkar-tenkale commented 3 years ago

Describe the bug Crash on setting image source uri

To Reproduce Steps to reproduce the behavior: CropImageView view = mDialog.getView().findViewById(R.id.cropImageView) cropImageView.setImageUriAsync(Uri.fromFile(myImageFile));

Expected behavior Load the image in cropview

Actual Behaviour Application crash with following stack trace

Additional context

   java.lang.ClassCastException: android.view.ContextThemeWrapper cannot be cast to androidx.fragment.app.FragmentActivity
        at com.canhub.cropper.CropImageView.setImageUriAsync(CropImageView.kt:734)
        at my.app.dialog.CropImageDialog.onInitDialog(CropImageDialog.java:53)
        at my.app.dialog.BottomDialog.onCreateDialog(BottomDialog.java:39)
        at androidx.fragment.app.DialogFragment.prepareDialog(DialogFragment.java:645)
        at androidx.fragment.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:559)
        at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1652)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:490)
        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2177)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2088)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1990)
        at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:594)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Canato commented 3 years ago

Hello @omkar-tenkale Welcome!

Could you please provide some more information?

On Steps to reproduce I cannot use this steps to reproduce =/ findViewbyId which id are you using? which view? is a library view? setImageUri() are you using this without parameter? we have 3 functions in this library that has this signature depending on how are you using. which one of them?

Thanks =D

omkar-tenkale commented 3 years ago

Issue title with a clear name for the bug: DialogFragment usage of CropImageView leads to crash (Sorry didn't see that before :P) Library version: 3.0.0 Which OS are you testing it : Android 11 LineageOS The code you used to call the library:

CropImageView view = mDialog.getView().findViewById(R.id.cropImageView)
cropImageView.setImageUriAsync(Uri.fromFile(myImageFile));

The code you add in your manifest to use the library

Manifest? Nothing

What Theme your app use for layout.

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">

I think the root cause of issue is using the view in DialogFragment androidx.fragment.app.DialogFragment

omkar-tenkale commented 3 years ago

https://github.com/Nescafemix/hintcase/issues/20#issuecomment-258070176

Canato commented 3 years ago

Hey @omkar-tenkale thank for exemplify more!

Indeed this is a context issue. Not sure if the library can support the usage of DialogFragment.

My suggestion would be to add a DialogFragment sample in our code base, in the sample module. So I can reproduce and you or another person can make the tweeks to make it work

stale[bot] commented 3 years ago

Let's keep this mess organised! This issue has been automatically marked as stale because it has not had recent activity. =( It will be closed if no further activity occurs. Thank you for your contributions.