IllegalStateException when trying to use view with createMethod = INFLATE
See original GitHub issueIn 1.4.6, code below that uses view binding delegate with CreateMethod.INFLATE
works as expected:
private val mainBinding: ActivityMainBinding by viewBinding(ActivityMainBinding::bind)
// Issue is in this binding
private val innerBinding: ItemToAddBinding by viewBinding(createMethod = CreateMethod.INFLATE)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mainBinding.rootLayout.setOnClickListener {
// Works fine in 1.4.6, but breaks in 1.5.3. Crashes on `innerBinding.itemButton`
mainBinding.rootLayout.addView(innerBinding.itemButton)
}
}
In 1.5.3 this code crashes with the following exception:
java.lang.IllegalStateException: Host view isn't ready to create a ViewBinding instance
at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.getValue(ViewBindingProperty.kt:87)
at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.getValue(ViewBindingProperty.kt:72)
at com.arsvechkarev.vbpdtest.MainActivity.getInnerBinding(MainActivity.kt:14)
at com.arsvechkarev.vbpdtest.MainActivity.onCreate$lambda-0(MainActivity.kt:20)
at com.arsvechkarev.vbpdtest.MainActivity.$r8$lambda$_81mDixuFKw3tx-DyH6RhN9DAAU(Unknown Source:0)
at com.arsvechkarev.vbpdtest.MainActivity$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I suspect that the problem is either in isViewInitialized
method in ActivityViewBindingProperty
, or in my code above. Any idea on how to fix this?
P.S I created a sample project where you can successfully reproduce this issue
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Getting Java illegal state Exception when trying to add View ...
1 Answer 1 ... @Badrinath That is because you use a RelativeLayout in the main.xml file instead of a LinearLayout with orientation set...
Read more >[Bug] CollectionView throws java.lang.IllegalStateException ...
Description I'm trying to use RemainingItemsThreshold and RemainingItemsThresholdReachedCommand to load more data on demand but I'm seeing ...
Read more >News — JRuby.org
Initial support for Rails 7. SQLite and MySQL are largely functional, but work remains to update them and PostgreSQL. JRuby 9.3.9.0 Released. Monday,...
Read more >'Check for updates now' throws 'Connection failed' error ...
It comes back with the error 'Connection failed. Please check your network connection and try again.' I can confirm that there is a...
Read more >android.view.InflateException: Binary XML file line #17 Code ...
InflateException : Binary XML file line when use ?attr/ ... IllegalStateException: Trying to create a platform view of unregistered type: plugins.flutter.io/ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In 1.5.6 I added functions that isn’t connected to Lifecycle of Activity. You can use them
viewBindingLazy()
orviewBindingWithLifecycle()
In your case
viewBinding
delegate by default connected with lifecycle of Activity. If it normal for you, continue to use it