diff --git a/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java b/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java index b5d8903b..50b83cdb 100644 --- a/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java +++ b/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java @@ -12,6 +12,7 @@ import android.widget.Filter; import android.widget.Filterable; import android.widget.TextView; +import android.widget.Toast; import com.pchmn.materialchips.ChipsInput; import com.pchmn.materialchips.R; @@ -58,17 +59,23 @@ public FilterableAdapter(Context context, ColorStateList textColor) { mContext = context; mRecyclerView = recyclerView; - Collections.sort(chipList, new Comparator() { - @Override - public int compare(ChipInterface o1, ChipInterface o2) { - Collator collator = Collator.getInstance(Locale.getDefault()); - collator.setStrength(Collator.PRIMARY); - return collator.compare(o1.getLabel(), o2.getLabel()); - } - }); - mOriginalList.addAll(chipList); - mChipList.addAll(chipList); - mFilteredList.addAll(chipList); + if(chipList == null) { + Log.e(TAG, "The filterable list is null"); + Toast.makeText(context, "The filterable list is null", Toast.LENGTH_LONG).show(); + } + else { + Collections.sort(chipList, new Comparator() { + @Override + public int compare(ChipInterface o1, ChipInterface o2) { + Collator collator = Collator.getInstance(Locale.getDefault()); + collator.setStrength(Collator.PRIMARY); + return collator.compare(o1.getLabel(), o2.getLabel()); + } + }); + mOriginalList.addAll(chipList); + mChipList.addAll(chipList); + mFilteredList.addAll(chipList); + } mLetterTileProvider = new LetterTileProvider(mContext); mBackgroundColor = backgroundColor; mTextColor = textColor; diff --git a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java index 3dc06d1e..a6b7ee14 100644 --- a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java +++ b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java @@ -31,7 +31,7 @@ public class ContactListActivity extends AppCompatActivity { @BindView(R.id.chips_input) ChipsInput mChipsInput; @BindView(R.id.validate) Button mValidateButton; @BindView(R.id.chip_list) TextView mChipListText; - private List mContactList = new ArrayList<>(); + private List mContactList; @Override protected void onCreate(Bundle savedInstanceState) { @@ -39,6 +39,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_contact_list); // butter knife ButterKnife.bind(this); + mContactList = new ArrayList<>(); // get contact list new RxPermissions(this)