gpt4 book ai didi

android - java.lang.IllegalStateException : view not added 错误

转载 作者:行者123 更新时间:2023-12-05 00:03:29 24 4
gpt4 key购买 nike

我收到以下异常。不明白为什么。也试过重现这个问题,但是没有成功。有人可以帮助我理解为什么我会遇到这个问题以及如何解决它。它也不是一直都在发生。

Fatal Exception: java.lang.IllegalStateException: view not added
at com.android.internal.policy.PhoneWindow.getViewRootImpl(PhoneWindow.java:1851)
at com.android.internal.policy.PhoneWindow.setLocalFocus(PhoneWindow.java:1835)
at com.qikwork.worker.views.fragment.MyBottomSheetFragment$onCreateView$1.onShow(MyBottomSheetFragment.java:53)
at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1465)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:7212)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:499)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

代码如下:

类 MyBottomSheetFragment() : BottomSheetDialogFragment(), ClockStatusBroadCastListener {...

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = DataBindingUtil.inflate(
inflater,
R.layout.my_bottomsheet,
container,
false
)

dialog!!.setOnShowListener { dia ->
val bottomSheetDialog = dia as BottomSheetDialog
val bottomSheetInternal: FrameLayout =
bottomSheetDialog.findViewById(com.google.android.material.R.id.design_bottom_sheet)!!
val bottomSheetBehaviour = BottomSheetBehavior.from(bottomSheetInternal)
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_EXPANDED
bottomSheetInternal.layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT
bottomSheetDialog.window?.setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN or
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
)
bottomSheetDialog.window?.setLocalFocus(true, true)
}
return binding.root
}.....

第 53 行指向 R.layout.my_bottomsheet

最佳答案

使用 setLocalFocus(true, true) 是导致问题的原因。删除它有效。

关于android - java.lang.IllegalStateException : view not added 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66470376/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com