简体   繁体   English

如果互联网关闭,则出现错误 java.lang.IllegalStateException: ScrollView can host only one direct child

[英]If internet is off getting error java.lang.IllegalStateException: ScrollView can host only one direct child

I am using NestedScrollView with single layout but they give me error like below when Internet is off, if internet on this is working fine.我正在使用具有单一布局的 NestedScrollView,但是如果 Internet 上的 Internet 工作正常,它们会在 Internet 关闭时给我如下所示的错误。

Process: com.oktested, PID: 8028
        java.lang.IllegalStateException: ScrollView can host only one direct child
            at androidx.core.widget.NestedScrollView.addView(NestedScrollView.java:444)
            at com.google.android.material.snackbar.BaseTransientBottomBar.showView(BaseTransientBottomBar.java:511)
            at com.google.android.material.snackbar.BaseTransientBottomBar$1.handleMessage(BaseTransientBottomBar.java:191)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:6662)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

XML Code: XML 代码:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/color_black">

        <androidx.core.widget.NestedScrollView
            android:id="@+id/nsvFaces"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:layout_marginTop="@dimen/_70sdp"
                    android:fontFamily="@font/roboto_regular"
                    android:text="@string/browsebyfaces"
                    android:textColor="@color/colorAccent"
                    android:textSize="@dimen/_24sdp"
                    android:layout_marginRight="@dimen/_10sdp"
                    android:textStyle="bold" />

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rvFaces"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:layout_marginTop="@dimen/_5sdp"
                    android:layout_marginRight="@dimen/_10sdp"
                    android:layout_marginBottom="@dimen/_10sdp"
                    android:nestedScrollingEnabled="false" />

            </LinearLayout>

        </androidx.core.widget.NestedScrollView>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/_70sdp"
                android:alpha="1"
                android:background="@drawable/bg_gradient_home" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/btnBack"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:padding="@dimen/_10sdp"
                    android:src="@drawable/ic_vector_arrow" />

                <RelativeLayout
                    android:id="@+id/sideMenu"
                    android:layout_width="@dimen/_50sdp"
                    android:layout_height="@dimen/_50sdp"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:padding="@dimen/_12sdp">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:src="@drawable/ic_menu_sky" />

                </RelativeLayout>

            </RelativeLayout>

        </RelativeLayout>

    </RelativeLayout>

I have also search more result but not getting proper solution and i have already try every solution from below link but not working in my case.我也搜索了更多结果,但没有得到正确的解决方案,我已经尝试了下面链接中的每个解决方案,但在我的情况下不起作用。

ScrollView can host only one direct child with relativelayout ScrollView 只能使用 relativelayout 托管一个直接子级
Scrollview can host only one direct child Scrollview 只能托管一个直接子级
A scroll view can have only one child Android XML file 一个滚动视图只能有一个子 Android XML 文件
java.lang.IllegalStateException: ScrollView can host only one direct child java.lang.IllegalStateException: ScrollView 只能承载一个直接子级

If I am wrong please suggest me and please help me.如果我错了,请建议我并帮助我。

at com.google.android.material.snackbar.BaseTransientBottomBar.showView(BaseTransientBottomBar.java:511)

Your stack trace tells me that you try to add a Snackbar to the ScrollView.您的堆栈跟踪告诉我您尝试将 Snackbar 添加到 ScrollView。

The Snackbar is tries to find a parent view where it can add its view. Snackbar 试图找到可以添加其视图的父视图。 You probably called the Snackbar.make() function with your ScrollView, so it tries to add the Snackbar there.您可能使用 ScrollView 调用了Snackbar.make() function,因此它会尝试在此处添加 Snackbar。 If you pass the RelativeLayout as a parent to the make function it will hopefully work.如果您将 RelativeLayout 作为父级传递给make function 它有望工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalStateException: Horizo​​ntalScrollView 只能承载一个直接子级 - java.lang.IllegalStateException: HorizontalScrollView can host only one direct child 当只有一个直接子项时,Java返回“ScrollView只能托管一个直接子项” - Java returns “ScrollView can host only one direct child” when there's only one direct child 获取java.lang.IllegalStateException:用于子视图 - Getting java.lang.IllegalStateException: for child view java.lang.IllegalStateException:启动孩子时出错 - java.lang.IllegalStateException: Error starting child 收到错误“java.lang.IllegalStateException:只能从活动打印”? - getting an error “java.lang.IllegalStateException: Can print only from an activity”? ScrollView只能容纳一个直子-Android - ScrollView can host only one direct child - android 将数据从活动传递到片段会导致“ ScrollView只能容纳一个直接子代”错误 - Passing data from activity to fragment causes “ScrollView can host only one direct child” error 如何解决此滚动视图错误“ScrollView can host only one direct child” - how to solve this scroll view error “ScrollView can host only one direct child” 如何做到这一点 ScrollView can host only an direct child androidx.core.widget.NestedScrollView 这个错误是由 - How to do this ScrollView can host only one direct child androidx.core.widget.NestedScrollView This error is caused by 无法在 tomcat 9 服务器中部署战争,出现错误 java.lang.IllegalStateException:启动子错误 - Unable to deploy war in tomcat 9 server getting error java.lang.IllegalStateException: Error starting child
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM