About java.util.NoSuchElementException errors when using set sets

Keywords: Java

Only to make a note of the new problems in using TagFlowLayout of Hongyang God in the development process!
Don't talk too much. Modify the adjusted code first

if (mBeanTagAdapter == null) {
        mBeanTagAdapter = new TagAdapter<CategoryBean>(mCategoryBeansList) {
            @Override
            public View getView(FlowLayout parent, final int position, CategoryBean str) {
                final View view;
                view = LayoutInflater.from(mActivity).inflate(R.layout.item_evaluation_history, null, false);
                final TextView textView = view.findViewById(R.id.tv_item_evaluation_history);
                textView.setText(str.getTitle());

                return view;
            }
        };
        mFlowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
                mSelectPosStr = mCategoryBeansList.get(position).getTitle();
                mEvaluateET.setText(mALLSelectEditStr);
                return true;
            }
        });
        mFlowLayout.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> selectPosSet) {
                //Get all selected position sets, such as [1,2,3,4]
                Set<Integer> selectedList = selectPosSet;
                mALLSelectEditStr = new StringBuffer("");
                for (Integer num : selectedList) {
                    LogUtil.e(TAG, num + " ");
                    mSelectPos=num;
                    mSelectPosStr = mCategoryBeansList.get(mSelectPos).getTitle();
                    mALLSelectEditStr.append(mSelectPosStr + " ");
                }

                mEvaluateET.setText(mALLSelectEditStr);
            }
        });
        mFlowLayout.setAdapter(mBeanTagAdapter);
    } else {
        mBeanTagAdapter.notifyDataChanged();
    }

Maybe I'll wonder as soon as I see this. It has something to do with what you said?? Uh huh? The above code is also changed by me. It is explained that the following problems appear in the multi select click event monitoring method, and the way to obtain the multi select click content is different, that is:

	Iterator<Integer> iterator = selectedList.iterator();
                for (iterator.hasNext();) {
                    LogUtil.e(TAG,"iterator.hasNext()="+iterator.next());
                    if (iterator.hasNext()){
                        mSelectPos=(int)iterator.next();
                        mSelectPosStr=mCategoryBeansList.get(mSelectPos).getTitle();
                        mALLSelectEditStr.append(mSelectPosStr);
                    }
                }

The java.util.NoSuchElementException exception will appear when running. The specific reason is that it can be found on the Internet without saying. The key is to know how to better solve this problem. In fact, it's also clear on the Internet, but for me, as a rookie, a closer look is not as good as a glance. The solution here: modify it directly in the for loop outside

for (Iterator<Integer> iterator = selectedList.iterator();iterator.hasNext();) 

Function! OK, but I found that writing like this is too troublesome, and debugging the data increases the amount of code, so I finally gave up the writing method.

Posted by Pobega on Wed, 25 Dec 2019 09:16:53 -0800