guolindev / PermissionX

An open source Android library that makes handling runtime permissions extremely easy.
Apache License 2.0
3.53k stars 406 forks source link

kotlin.UninitializedPropertyAccessException #36

Closed awhhz20 closed 4 years ago

awhhz20 commented 4 years ago

由InvisibleFragment private lateinit PermissionBuilder 引发 kotlin.UninitializedPropertyAccessException 异常 关键字lateinit 引起 导致未初始化成功 permissionBuilder 为Null

guolindev commented 4 years ago

最好能提供一下堆栈信息,或者你使用的版本号。

因为这个问题在后面的版本解决过,没有堆栈信息我不好判断是新的问题,还是之前解决过的老问题。

你可以参考一下这条issue https://github.com/guolindev/PermissionX/issues/2

awhhz20 commented 4 years ago

好的
版本是我从添加自定义窗口前一个版本 我是把代码cory到我本地的 java.lang.RuntimeException:Unable to resume activity {com.homeking365.staffclean/hk.staff.module.home.home.HomeActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=393218, result=0, data=null} to activity {com.homeking365.staffclean/hk.staff.module.home.home.HomeActivity}: kotlin.UninitializedPropertyAccessException: lateinit property permissionBuilder has not been initialized

2 android.app.ActivityThread.performResumeActivity(ActivityThread.java:4902) 3 ...... 4 kotlin.UninitializedPropertyAccessException:lateinit property permissionBuilder has not been initialized 5 hk.lib.permission.permissionx.InvisibleFragment.void onActivityResult(int,int,android.content.Intent)(InvisibleFragment.kt:185) 6 androidx.fragment.app.FragmentActivity.void onActivityResult(int,int,android.content.Intent)(FragmentActivity.java:170) 7 android.app.Activity.dispatchActivityResult(Activity.java:8412) 8 android.app.ActivityThread.deliverResults(ActivityThread.java:5580) 9 android.app.ActivityThread.performResumeActivity(ActivityThread.java:4889) 10 android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4945) 11 android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) 12 android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:190) 13 android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:105) 14 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473) 15 android.os.Handler.dispatchMessage(Handler.java:110) 16 android.os.Looper.loop(Looper.java:219) 17 android.app.ActivityThread.main(ActivityThread.java:8347) 18 java.lang.reflect.Method.invoke(Native Method) 19 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 20 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)

guolindev commented 4 years ago

额,你这一拷过到你本地之后,我不知道InvisibleFragment.kt:185行对应的是什么代码了。你能把这段代码的前后代码都贴出来一下吗?

awhhz20 commented 4 years ago

这是从 128 到 206的代码 permissionBuilder?.let { pb -> if (requestCode == PERMISSION_CODE) { val grantedList = ArrayList() // holds granted permissions in the request permissions val showReasonList = ArrayList() // holds denied permissions in the request permissions. val forwardList = ArrayList() // hold permanently denied permissions in the request permissions. for ((index, result) in grantResults.withIndex()) { // iterate all granted results if (result == PackageManager.PERMISSION_GRANTED) { grantedList.add(permissions[index]) // Remove granted permissions from deniedPermissions and permanentDeniedPermissions set in PermissionBuilder. pb.deniedPermissions.remove(permissions[index]) pb.permanentDeniedPermissions.remove(permissions[index]) } else { // Denied permission can turn into permanent denied permissions, but permanent denied permission can not turn into denied permissions. val shouldShowReason = shouldShowRequestPermissionRationale(permissions[index]) if (shouldShowReason) { showReasonList.add(permissions[index]) pb.deniedPermissions.add(permissions[index]) // So there's no need to remove the current permission from permanentDeniedPermissions because it won't be there. } else { forwardList.add(permissions[index]) pb.permanentDeniedPermissions.add(permissions[index]) // We must remove the current permission from deniedPermissions because it is permanent denied permission now. pb.deniedPermissions.remove(permissions[index]) } } } // We can never holds granted permissions for safety, because user may turn some permissions off in Settings. // So every time request, must request the already granted permissions again and refresh the granted permission set. pb.grantedPermissions.clear() pb.grantedPermissions.addAll(grantedList) val allGranted = pb.grantedPermissions.size == pb.allPermissions.size if (allGranted) { // If all permissions are granted, call RequestCallback directly. requestCallback(true, pb.allPermissions, listOf()) } else { var goesToRequestCallback = true // If there's need goes to RequestCallback // If explainReasonCallback is not null and there're denied permissions. Try the ExplainReasonCallback. if ((explainReasonCallback != null || explainReasonCallback2 != null) && showReasonList.isNotEmpty()) { goesToRequestCallback = false // No need cause ExplainReasonCallback handles it explainReasonCallback2?.let { // callback ExplainReasonCallback2 prior to ExplainReasonCallback pb.explainReasonScope.it(showReasonList, false) } ?: explainReasonCallback?.let { pb.explainReasonScope.it( showReasonList ) } } // If forwardToSettingsCallback is not null and there're permanently denied permissions. Try the ForwardToSettingsCallback. else if (forwardToSettingsCallback != null && forwardList.isNotEmpty()) { goesToRequestCallback = false // No need cause ForwardToSettingsCallback handles it forwardToSettingsCallback?.let { pb.forwardToSettingsScope.it( forwardList ) } } // If showRequestReasonDialog or showForwardToSettingsDialog is not called. Try the RequestCallback. // There's case that ExplainReasonCallback or ForwardToSettingsCallback is called, but developer didn't invoke // showRequestReasonDialog or showForwardToSettingsDialog in the callback. // At this case and all other cases, RequestCallback will be called. if (goesToRequestCallback || !pb.showDialogCalled) { val deniedList = ArrayList() deniedList.addAll(pb.deniedPermissions) deniedList.addAll(pb.permanentDeniedPermissions) requestCallback( false, pb.grantedPermissions.toList(), deniedList ) } } } }

guolindev commented 4 years ago

你能用截图的方式提供,并且把行号截出来吗,这样我根本没法看185行代码是什么。

而且根据你发出来的错误堆栈,崩溃是发生在onActivityResult这个函数里面的,你上面贴出来的代码没有这个函数。

guolindev commented 4 years ago

由于没有进一步回复,此问题暂时关闭。