开发者社区> 问答> 正文

迁移androidx和android sdk 29后崩溃了吗?

迁移到androidX后,出现异常

E/UncaughtException: java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
    at android.widget.ListView.clearRecycledState(ListView.java:545)
    at android.widget.ListView.resetList(ListView.java:531)
    at android.widget.ListView.layoutChildren(ListView.java:1556)
    at android.widget.AbsListView.onLayout(AbsListView.java:2170)
    at android.view.View.layout(View.java:17666)
    at android.view.ViewGroup.layout(ViewGroup.java:5577)
    at androidx.swiperefreshlayout.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:625)
    at android.view.View.layout(View.java:17666)
    at android.view.ViewGroup.layout(ViewGroup.java:5577)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
    at android.view.View.layout(View.java:17666)
    at android.view.ViewGroup.layout(ViewGroup.java:5577)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:17666)
    at android.view.ViewGroup.layout(ViewGroup.java:5577)
    at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:444)
    at android.view.View.layout(View.java:17666)
    at android.view.ViewGroup.layout(ViewGroup.java:5577)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:17666)
    at android.view.ViewGroup.layout(ViewGroup.java:5577)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
    at android.view.View.layout(View.java:17666)
    at android.view.ViewGroup.layout(ViewGroup.java:5577)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at com.android.internal.policy.DecorView.onLayout(DecorView.java:730)
    at android.view.View.layout(View.java:17666)
    at android.view.ViewGroup.layout(ViewGroup.java:5577)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2383)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2105)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1291)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6396)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:876)
    at android.view.Choreographer.doCallbacks(Choreographer.java:688)
    at android.view.Choreographer.doFrame(Choreographer.java:623)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:862)
    at android.os.Handler.handleCallback(Handler.java:754)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:163)
    at android.app.ActivityThread.main(ActivityThread.java:6228)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)

我使用SwipeRefreshLayout的PullAndLoadListView

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/appbackground"
android:orientation="vertical" >

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.org.appname.view.PullAndLoadListView
        android:id="@+id/listFeed"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/include1"
        android:layout_alignParentTop="true"
        android:paddingBottom="50dp">
    </com.org.appname.view.PullAndLoadListView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

<include
    android:id="@+id/include1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:layout_margin="5dp"
    layout="@layout/buttons_bottom" /></RelativeLayout>

尝试了这么多StackOverflow答案,但没有一个对我有帮助吗?

编辑 我能够追踪这个问题,实际上在SwipeRefreshLayout.java方法名称onLayout的这行崩溃了child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);。

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    final int width = getMeasuredWidth();
    final int height = getMeasuredHeight();
    if (getChildCount() == 0) {
        return;
    }
    if (mTarget == null) {
        ensureTarget();
    }
    if (mTarget == null) {
        return;
    }
    final View child = mTarget;
    final int childLeft = getPaddingLeft();
    final int childTop = getPaddingTop();
    final int childWidth = width - getPaddingLeft() - getPaddingRight();
    final int childHeight = height - getPaddingTop() - getPaddingBottom();
    child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
    int circleWidth = mCircleView.getMeasuredWidth();
    int circleHeight = mCircleView.getMeasuredHeight();
    mCircleView.layout((width / 2 - circleWidth / 2), mCurrentTargetOffsetTop,
            (width / 2 + circleWidth / 2), mCurrentTargetOffsetTop + circleHeight);
}

展开
收起
Puppet 2019-12-04 15:35:21 2072 0
1 条回答
写回答
取消 提交回答
  • 参考: https://stackoverflow.com/questions/21045198/android-view-viewgrouplayoutparams-cannot-be-cast-to-android-widget-abslistview

    2019-12-13 15:50:53
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
从 SDK 到编解码:视频直播架构解析 立即下载
跨平台的云服务SDK需要什么 立即下载
一个跨平台的云服务SDK需要什么 立即下载