Android RecyclerView 报错:java.lang.IllegalStateException: The specified child already has a...

报错信息:

   java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

解决办法:

由原来

 @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(mInflater.inflate(
                R.layout.item, parent));
        return holder;
    }

改为:

  @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(mInflater.inflate(
                R.layout.item, parent,false));
        return holder;
    }

2018/07/18
IllegalStateException
顾名思义,这个是非法状态异常,所以可以从报错的仔细查找原因

你可能感兴趣的:(Android)