RecyclerView NullPointerException Issue in getItemCount

后端 未结 1 980
灰色年华
灰色年华 2021-01-21 04:14

Please look into this and let me know what went wrong.

public class MyAdapter extends RecyclerView.Adapter {
    private ItemData[]         


        
相关标签:
1条回答
  • 2021-01-21 05:07

    Your itemsData parameter passed to the MyAdapter's constructor is null or you are using the second constructor which is not initializes the itemsData class member. You can check it for null and return 0 from the getItemCount method:

    @Override
    public int getItemCount() {
        return itemsData == null ? 0 : itemsData.length;
    }
    
    0 讨论(0)
提交回复
热议问题