Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
659 views
in Technique[技术] by (71.8m points)

java - ClassCastException: androidx.viewpager.widget.ViewPager$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

It's okay when it runs in android with API 28. But when switching to API 23 it shows ClassCastException. Here's my code

Here's the Java code snippet

private void setUpListView(){
        ExpandableListView expandableListView = view.findViewById(R.id.fragment_transaction_viewpager_expandablelistview);
        expandableListView.setVisibility(View.GONE);
        listView = view.findViewById(R.id.fragment_transaction_viewpager_listview);
        // per item kalau diclick
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                viewWallet(id);
            }
        });
        listView.addHeaderView(header, null, false);

        setUpAdapter();
    }
private void setUpAdapter(){
        adapter = new WalletAdapter(fragment.getActivity(), null);
        listView.setAdapter(adapter);
    }

The WalletAdapter extends CursorAdapter

Here's the error log

java.lang.ClassCastException: androidx.viewpager.widget.ViewPager$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
        at android.widget.ListView.clearRecycledState(ListView.java:543)
        at android.widget.ListView.resetList(ListView.java:529)
        at android.widget.ListView.setAdapter(ListView.java:473)
        at com.example.duitku.wallet.fragment.WalletFragmentView.setUpAdapter(WalletFragmentView.java:124)
        at com.example.duitku.wallet.fragment.WalletFragmentView.setUpListView(WalletFragmentView.java:113)
        at com.example.duitku.wallet.fragment.WalletFragmentView.setUpUI(WalletFragmentView.java:50)
        at com.example.duitku.wallet.fragment.WalletFragment.onCreateView(WalletFragment.java:30)

Thank you in advance! I appreciate every answer

question from:https://stackoverflow.com/questions/65886367/classcastexception-androidx-viewpager-widget-viewpagerlayoutparams-cannot-be-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...