Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in Scrollview

In my android application, I'm facing a IllegalStateException. I can't reproduce this exception later. This is the stacktrace

Non-fatal Exception: java.lang.IllegalStateException: ScrollView can host only one direct child
       at android.widget.ScrollView.addView(ScrollView.java:397)
       at android.support.design.widget.BaseTransientBottomBar.showView(BaseTransientBottomBar.java:436)
       at android.support.design.widget.BaseTransientBottomBar$1.handleMessage(BaseTransientBottomBar.java:178)
       at android.os.Handler.dispatchMessage(Handler.java:98)
       at android.os.Looper.loop(Looper.java:146)
       at android.app.ActivityThread.main(ActivityThread.java:5679)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
       at dalvik.system.NativeStart.main(NativeStart.java)  

Anyone please help me!

like image 860
vm345 Avatar asked Mar 08 '23 21:03

vm345


2 Answers

I examined the question carefully, and I logically found that it is related to showing Snackbar on a fragment or activity, taken as a reference in another class as global object, when it is invalidated in onStop(), onDestroy() life cycle callback stage respectively:

https://stackoverflow.com/a/52019719/787399

like image 136
Abhinav Saxena Avatar answered Mar 24 '23 08:03

Abhinav Saxena


Inside your ScrollView you have to host a child (e.g. a Linear Layout) which at it's time will host all the UI elements from that scrollview. You can't have, for example, 2 textviews added directly to a ScrollView. You need to have something to hold those UI elements inside the scrollview.

like image 23
Gabi Avatar answered Mar 24 '23 07:03

Gabi