简体   繁体   English

AbsSavedState$1 不能转换为 android.widget.ScrollView$SavedState

[英]AbsSavedState$1 cannot be cast to android.widget.ScrollView$SavedState

I am using navigation components in my Android Project .I am using One Activity model and following this model I have 1 Base Activity and the rest are all Fragments .我在我的Android 项目中使用导航组件。我使用One Activity 模型并遵循此模型我有 1 个基本活动,其余都是Fragments
My problem comes on pressing the back button when i have to move to back to a previous fragment.I have Scroll view in my fragment named WorkerAnalyticsFragment shown below.我的问题是在我必须返回到前一个片段时按下后退按钮。我在名为WorkerAnalyticsFragment 的片段中有滚动视图,如下所示。

在此处输入图片说明

The Container shown in the center contains the Scroll view as the root view to scroll the contents inside container when Order analytics and Motivation analytics are expand to show details.The xml code of the fragment_worker_analytics is shown below.在中心示出的容器包含滚动视图为根视图滚动内部容器中的内容时,订单分析动机分析被展开显示的fragment_worker_analytics的details.The XML代码如下所示。

<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    tools:context=".Fragment.WorkerAnalyticsFragment"
    android:background="@color/uniform_background">

    <LinearLayout
        android:id="@+id/profile_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="@dimen/profile_container_margin_top">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/circle_image_view_large"
            android:layout_width="@dimen/circle_image_view_large_width"
            android:layout_height="@dimen/circle_image_view_large_height"
            android:src="@drawable/example_avatar"
            android:layout_gravity="center_horizontal"/>

        <androidx.appcompat.widget.AppCompatTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/text_view_profile_name"
            android:maxLines="1"
            android:layout_gravity="center_horizontal"
            style="@style/UniformTextAppearance"/>

    </LinearLayout>

    <include layout="@layout/analytics_container" android:id="@+id/analytics_container"/>

    <include layout="@layout/order_and_report_buttons" android:id="@+id/order_and_report_buttons"/>

</LinearLayout>

</layout>

The xml code of the analytics_container which is shown in the center in the above picture is here.上图中中间显示的analytics_container的xml代码在这里。

<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

<ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="350dp"
    android:layout_margin="@dimen/analytics_container_margin"
    android:background="@drawable/container_background"
    android:minHeight="350dp"
    android:scrollbars="none"
    android:padding="@dimen/analytics_container_padding">

    <LinearLayout
        android:id="@+id/analytics_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/current_order_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/text_view_current_order_status_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/text_view_current_order_status_text"
                android:textStyle="bold"
                style="@style/UniformTextAppearance"/>

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center">

                <LinearLayout
                    android:id="@+id/current_order_details_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_marginTop="@dimen/step_view_margin_top"
                    android:visibility="visible">

                    <com.kofigyan.stateprogressbar.StateProgressBar
                        android:id="@+id/order_progress_bar"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:spb_maxStateNumber="four"
                        app:spb_stateDescriptionSize="@dimen/sbp_state_description_text_size"
                        app:spb_maxDescriptionLines="1"
                        app:spb_stateBackgroundColor="@color/spb_state_background_color"
                        app:spb_stateForegroundColor="@color/spb_state_foreground_color"
                        app:spb_descriptionTopSpaceIncrementer="@dimen/spb_description_top_Space_incrementer"
                        app:spb_currentStateDescriptionColor="@color/spb_current_state_description_color"
                        app:spb_stateDescriptionColor="@color/spb_state_description_color"
                        app:spb_stateNumberBackgroundColor="@color/spb_state_number_background_color"/>

                    <include layout="@layout/current_item" android:id="@+id/current_item"/>

                </LinearLayout>

                <TextView
                    android:id="@+id/empty_text_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/no_current_order_text"
                    android:textSize="@dimen/empty_text_size"
                    android:textStyle="bold"
                    android:layout_gravity="center"
                    android:visibility="invisible"
                    android:background="@color/current_item_container_background_color"
                    style="@style/EmptyTextAppearance"
                    />

            </FrameLayout>

        </LinearLayout>

        <LinearLayout
            android:id="@+id/profile_analytics_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginTop="@dimen/profile_container_margin_top">

            <TextView
                android:id="@+id/text_view_worker_analytics"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/text_view_worker_analytics_text"
                android:textStyle="bold"
                style="@style/UniformTextAppearance"/>

            <include layout="@layout/card_view_analytics_container"/>

        </LinearLayout>

    </LinearLayout>

</ScrollView>

</layout>

I have another fragment named OrderFragment which comes out when the user clicks ORDER button as shown in above picture.Here is the picture.我有另一个名为OrderFragment 的片段,当用户单击上图所示的ORDER按钮时它会出现。这是图片。

在此处输入图片说明

The code of the OrderFragment is shown below. OrderFragment的代码如下所示。

<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<LinearLayout
    android:id="@+id/stock_fragment_parent_layout_padding"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="@dimen/stock_fragment_parent_layout_padding"
    android:background="@color/uniform_background"
    tools:context=".Fragment.OrderFragment">

    <LinearLayout
        android:id="@+id/stock_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical"
        android:layout_marginTop="@dimen/stock_container_margin_top"
        android:background="@drawable/container_background">

        <TextView
            android:id="@+id/text_view_available_stock_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="@string/text_view_available_stock_text"
            style="@style/UniformTextAppearance"/>

        <LinearLayout
            android:id="@+id/stock_list_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="@dimen/stock_list_container_margin_top">

            <include layout="@layout/recycler_view" android:id="@+id/recycler_view"/>

        </LinearLayout>

    </LinearLayout>



</LinearLayout>

</layout>

The problem comes when i press the Back button to return to the previous WorkerAnayticsFragment shown above by xml code and by picture, my application crashes.当我按“后退”按钮返回到上面通过 xml 代码和图片显示的上一个WorkerAnayticsFragment时,问题出现了,我的应用程序崩溃了。
Here is my Log cat showing the error when application crash.这是我的 Log cat 显示应用程序崩溃时的错误。

2020-03-27 01:26:57.757 20708-20708/com.example.nibotransporti E/AndroidRuntime: FATAL EXCEPTION: 
 main
Process: com.example.nibotransporti, PID: 20708
java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to 
    android.widget.ScrollView$SavedState
    at android.widget.ScrollView.onRestoreInstanceState(ScrollView.java:1872)
    at android.view.View.dispatchRestoreInstanceState(View.java:17819)
    at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3773)
    at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3781)
    at android.view.View.restoreHierarchyState(View.java:17797)
    at androidx.fragment.app.Fragment.restoreViewState(Fragment.java:574)
    at androidx.fragment.app.FragmentStateManager.restoreViewState(FragmentStateManager.java:505)
    at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1164)
    at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2209)
    at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1976)
    at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1915)
    at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1811)
    at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:427)
    at android.os.Handler.handleCallback(Handler.java:808)
    at android.os.Handler.dispatchMessage(Handler.java:101)
    at android.os.Looper.loop(Looper.java:166)
    at android.app.ActivityThread.main(ActivityThread.java:7529)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
    2020-03-27 01:26:57.799 20708-20708/com.example.nibotransporti I/Process: Sending signal. PID: 
    20708 SIG: 9

I am in a serious trouble.Please help me by suggesting me a robust solution.我遇到了严重的麻烦。请向我建议一个强大的解决方案来帮助我。

your code is not complete,but I guess you used the same id for view.您的代码不完整,但我猜您使用了相同的 ID 进行查看。

when this fragment rebuild,these same id might lead to the problem.当这个片段重建时,这些相同的 id 可能会导致问题。

you can try to change the id of scrollView,should be solved可以尝试更改scrollView的id,应该可以解决

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

相关问题 java.lang.ClassCastException:android.widget.ScrollView无法强制转换为android.widget.TextView - java.lang.ClassCastException: android.widget.ScrollView cannot be cast to android.widget.TextView 无法将Textview强制转换为android.widget.listview - Textview cannot be cast to android.widget.listview 无法转换为android.widget.AdapterView $ OnItemSelectedListener - cannot be cast to android.widget.AdapterView$OnItemSelectedListener 无法将ProfilePictureView强制转换为android.widget.ImageView - ProfilePictureView cannot be cast to android.widget.ImageView ConstraintLayout 不能转换为 android.widget.TextView - ConstraintLayout cannot be cast to android.widget.TextView 无法将ImageButton强制转换为android.widget.Edittext - ImageButton cannot be cast to android.widget.Edittext 无法将Android.widget.RelativeLayout强制转换为android.widget.ImageView - Android.widget.RelativeLayout cannot be cast to android.widget.ImageView Android小部件相对布局无法强制转换为Android小部件textview - Android widget relativelayout cannot be cast to android widget textview android.widget.TableLayout无法强制转换为android.widget.TableRow - android.widget.TableLayout cannot be cast to android.widget.TableRow android.widget.TextView无法转换为android.widget.EditText 5 - android.widget.TextView cannot be cast to android.widget.EditText 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM