-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IllegalStateException when using viewBinding for onCreateView #101
Comments
Please try version 1.5.6 |
I've have been facing the same issue with version 1.5.6 |
@gabrielfeo from what places you access viewBinding delegate? |
@kirich1409 I could replicate the problem using the sample app adjusting the way we setup the Fragment view. Instead of referecing the xml, using the Binding generated class from:
to:
|
Is it possible to fix this without removing the XML referencing? |
@kirich1409 In my case, I'm accessing the |
Yes. |
Another variant is class ProfileFragment : Fragment() {
private val viewBinding: ProfileBinding by viewBinding(createMethod = CreateMethod.INFLATE)
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
) = viewBinding.root
} it will work because ViewBindingPropdetyDelegate will call ViewBinding.inflate method via reflection. It's slower and not recommended. Prefer to use class ProfileFragment : Fragment(R.layout.profile) {
private val viewBinding: ProfileBinding by viewBinding(ProfileBinding::bind)
} |
By default the library prevent using |
@kirich1409 Crash happened on android 13, 14 version which is using viewBinding delegate 1.5.9 version . I used this type
I replaced this code part it worked:
|
any updates on this issue ? |
|
I understand the issue. Try to reproduce it and fix on weekend |
As solution I recommend to set XML layout in Fragment constructor and use ViewBindingDelegate without without inflating view and it will wrap Fragment.getView() |
Trying to update to 1.5.2+, I find this usage causes a crash due to a new internal check in the library.
The change is stated in the changelog, but I don't see anything inherently wrong with the above usage considering the viewBinding lambda is invoked lazily. Do you see a way to keep it (we have many in the project) when upgrading to 1.5.2+?
The text was updated successfully, but these errors were encountered: