Issue
I am using ScrollView
in my Android Layout but it shows
IllegalStateException "Scrollview can host only one direct child"
How can I avoid this exception?
Crash info:
07-19 15:58:22.308 21372 21372 D AndroidRuntime: Shutting down VM
07-19 15:58:22.313 21372 21372 E AndroidRuntime: FATAL EXCEPTION: main
07-19 15:58:22.313 21372 21372 E AndroidRuntime: Process: com.languoguang.helloworld, PID: 21372
07-19 15:58:22.313 21372 21372 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.languoguang.helloworld/com.languoguang.helloworld.plugin_homeadd.activity.AddDeviceWifiSettingActivity}: android.view.InflateException: Binary XML file line #254: ScrollView can host only one direct child
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3190)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3285)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.ActivityThread.-wrap12(Unknown Source:0)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:108)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.os.Looper.loop(Looper.java:166)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7412)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:926)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #254: ScrollView can host only one direct child
07-19 15:58:22.313 21372 21372 E AndroidRuntime: Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.widget.ScrollView.addView(ScrollView.java:292)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:878)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:477)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at com.android.internal.policy.HwPhoneWindow.setContentView(HwPhoneWindow.java:313)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.Activity.setContentView(Activity.java:2843)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at com.languoguang.helloworld.plugin_homeadd.activity.AddDeviceWifiSettingActivity.onCreate(AddDeviceWifiSettingActivity.java:82)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7358)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3143)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3285)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.ActivityThread.-wrap12(Unknown Source:0)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:108)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.os.Looper.loop(Looper.java:166)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7412)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:926)
Solution
You have added more than one controls as children of a ScrollView
. If you want to do this add a LinearLayout
as a direct child and put the other controls in it.
Answered By - kgiannakakis
Answer Checked By - Gilberto Lyons (JavaFixing Admin)