WindSekirun / NaraeImagePicker

MultiImagePicker for Android Application, written in Kotlin
Apache License 2.0
40 stars 14 forks source link

Crash after picking images from gallery #27

Open fabdurso opened 4 years ago

fabdurso commented 4 years ago

kotlin.UninitializedPropertyAccessException: lateinit property _callback has not been initialized at com.github.windsekirun.naraeimagepicker.NaraeImagePicker$ResultFragment.access$get_callback$p(NaraeImagePicker.kt:54) at com.github.windsekirun.naraeimagepicker.NaraeImagePicker$ResultFragment$onActivityResult$1.invoke(NaraeImagePicker.kt:69) at com.github.windsekirun.naraeimagepicker.NaraeImagePicker$ResultFragment$onActivityResult$1.invoke(NaraeImagePicker.kt:54)

Was not happening until a few days ago.

Gradle version: 3.6.0

fabdurso commented 4 years ago

@WindSekirun @deepakkumardk ever seen this?

deepakkumardk commented 4 years ago

@thefabbulus Is this happening every time or just a one time crash. This could happen when you use restart activity or apply changes options.

fabdurso commented 4 years ago

@deepakkumardk always.

fabdurso commented 4 years ago

@deepakkumardk noticed that this is only happening on a real device, and not happening on a virtual device.


NaraeImagePicker.instance.start(
    ActivityUtils.getTopActivity(), pickerOption,
        object : OnPickResultListener {
            override fun onSelect(resultCode: Int, imageList: ArrayList<String>) {
                if (resultCode != NaraeImagePicker.PICK_SUCCESS) {
                    single.onError(Error("Operation canceled!"))
                } else {
                    single.onSuccess(imageList.map { File(it) })
                }
            }
        }
    )
deepakkumardk commented 4 years ago

@thefabbulus could you please provide the implementation of ActivityUtils.getTopActivity() and pickerOption.

fabdurso commented 4 years ago

@deepakkumardk

public static Activity getTopActivity() {
    return Utils.getActivityLifecycle().getTopActivity();
}
val pickerOption = PickerSettingItem().apply {
    pickLimit = 3
    viewMode = ViewMode.FolderView
    enableDetailMode = true
    uiSetting.enableUpInParentView = true
}
WindSekirun commented 4 years ago

@thefabbulus @deepakkumardk

Sorry, I can't check this issue because notifications doesn't delivered. Probably, I guess the implementation of getActivityLifecycle() is the problem. Can you tell me why you are using getActivityLifecycle() instead of this?

deepakkumardk commented 4 years ago

@thefabbulus Are you using some library for getTopActivity(). Please, mention the library too. Most probably this could be the cause of the error. To fix the issue try to use fragment/activity context or applicationcontext, if this happens again let me know. I will update this thread on this issue.

fabdurso commented 4 years ago

@deepakkumardk weird since it was working good until last week.

Activity getTopActivity() {
    if (!mActivityList.isEmpty()) {
        for (int i = mActivityList.size() - 1; i >= 0; i--) {
            Activity activity = mActivityList.get(i);
            if (activity == null || activity.isFinishing() || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed())) {
                continue;
            }
            return activity;
        }
    }
    Activity topActivityByReflect = getTopActivityByReflect();
    if (topActivityByReflect != null) {
        setTopActivity(topActivityByReflect);
    }
    return topActivityByReflect;
}
deepakkumardk commented 4 years ago

@thefabbulus I have tested the app with library AndroidUtilCode's (v1.26.0) method getTopActivity() with one activity stack (without any fragment, what's your scenario) and it's working fine in my real device.

sagar-docterz commented 3 years ago

@deepakkumardk here is a screenshot of the crash report

Screen Shot 2020-09-10 at 8 06 44 PM

deepakkumardk commented 3 years ago

@sagar-docterz could you please provide the sample code that you are using to start the Picker.