ScrollView cannot contain multiple subkeys, ScrollView can host only one direct child

Source: Internet
Author: User

http://debuglog.iteye.com/blog/1441828

ScrollView cannot contain multiple subkeys, ScrollView can host only one direct child Blog Category:
    • Android
    • Eclipse
javaandroideclipsescrollviewillegalstateexceptionhtml Code
    1. Android 2.3.3
    2. Eclipse version:3.7.0
    3. LogCat

LogCat error message:

Java code
  1. 03-: 11.126:error/androidruntime (17173): caused by:java.lang.IllegalStateException: ScrollView can host only one direct child
  2. 03-: 11.126:error/androidruntime (17173): at Android.widget.ScrollView.addView ( Scrollview.java:229)
  3. 03-: 11.126:error/androidruntime (17173): at Android.view.LayoutInflater.rInflate ( Layoutinflater.java:627)
  4. 03-: 11.126:error/androidruntime (17173): at Android.view.LayoutInflater.rInflate ( Layoutinflater.java:626)
  5. 03-: 11.126:error/androidruntime (17173): at Android.view.LayoutInflater.inflate ( Layoutinflater.java:408)
  6. 03-: 11.126:error/androidruntime (17173): at Android.view.LayoutInflater.inflate ( Layoutinflater.java:)
  7. 03-: 11.126:error/androidruntime (17173): at Android.view.LayoutInflater.inflate ( Layoutinflater.java:276)
  8. 03-: 11.126:error/androidruntime (17173): at Com.android.internal.policy.impl.PhoneWindow.setContentView (Phonewindow.java:207)
  9. 03-: 11.126:error/androidruntime (17173): at Android.app.Activity.setContentView ( Activity.java:1657)
  10. 03-: 11.126:error/androidruntime (17173): at Com.tmall.nokia.manage.CopyRight.onResume (Copyright.java:)
  11. 03-: 11.126:error/androidruntime (17173): at Android.app.Instrumentation.callActivityOnResume (Instrumentation.java:1150)
  12. 03-: 11.126:error/androidruntime (17173): at Android.app.Activity.performResume ( Activity.java:3832)
  13. 03-: 11.126:error/androidruntime (17173): at Android.app.ActivityThread.performResumeActivity (Activitythread.java:2110)
  14. 03-: 11.126:error/androidruntime (17173): ... More

Cause analysis of error occurred:

ScrollView only supports one subkey.

View the corresponding layout xml

Java code
  1. <scrollview xmlns:android="Http://schemas.android.com/apk/res/android"
  2. Android:layout_width= "fill_parent" android:layout_height="wrap_content "
  3. android:scrollbars="vertical" >
  4. <textview android:id="@+id/nokia" android:layout_gravity="center"
  5. Android:layout_width= "fill_parent" android:layout_height="wrap_content "
  6. Android:textappearance="? Android:attr/textappearancemedium"
  7. android:text="@string/text_nokia" ></TextView>
  8. <textview android:id="@+id/iphone4s" android:layout_gravity="center"
  9. Android:layout_width= "wrap_content" android:layout_height="wrap_content "
  10. android:text="@string/text_iphone4s" ></TextView>
  11. </ScrollView>

There are two TextView subkeys found in ScrollView.

Workaround:

Set LinearLayout as child in ScrollView, and put other view in LinearLayout.

Java code
  1. <scrollview xmlns:android="Http://schemas.android.com/apk/res/android"
  2. Android:layout_width= "fill_parent" android:layout_height="wrap_content "
  3. android:scrollbars="vertical" >
  4. <linearlayout android:id="@+id/tmall"
  5. Android:layout_width= "fill_parent" android:layout_height="wrap_content "
  6. android:orientation="vertical" >
  7. <textview android:id="@+id/nokia" android:layout_gravity="center"
  8. Android:layout_width= "fill_parent" android:layout_height="wrap_content "
  9. Android:textappearance="? Android:attr/textappearancemedium"
  10. android:text="@string/text_nokia" ></TextView>
  11. <textview android:id="@+id/iphone4s" android:layout_gravity="center"
  12. Android:layout_width= "wrap_content" android:layout_height="wrap_content "
  13. android:text="@string/text_iphone4s" ></TextView>
  14. </LinearLayout>
  15. </ScrollView>

Ps. When editing the layout XML, be aware of the "Error Log" window and the "Graphical Layout" tab of the Layout XML editing window.

ScrollView cannot contain multiple subkeys, ScrollView can host only one direct child

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.