Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // I have created this SearchActivity based on a RecyclerView but when I click on an Item on the list I get a NPE:
- /* java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.ArrayList.get(int)' on a null object reference */
- the error is caused by this part of code:
- ItemClickSupport.addTo(rv).setOnItemClickListener(new ItemClickSupport.OnItemClickListener(){
- @Override
- public void onItemClicked(RecyclerView recyclerView, int position, View v) {
- Intent intent = new Intent(SearchActivity.this, ChordActivity.class);
- Bundle bundle = new Bundle();
- bundle.putParcelable("selected", filteredModelList.get(position)); //HERE IS THE ERROR
- intent.putExtras(bundle);
- startActivity(intent);
- }
- });
- The filter it is based on is this one:
- private List<Accordo> filter(List<Accordo> models, String query) {
- query = query.toLowerCase();
- filteredModelList = new ArrayList<>();
- for (Accordo model : models) {
- final String text = model.getName().toLowerCase();
- if (text.contains(query)) {
- filteredModelList.add(model);
- }
- }
- return filteredModelList;
- }
- IMPORTANT: the error accours ONLY when I got the whole list, when it is NOT FILTERED. If I type anything and filter the list and then click on the Item the error does not accour.
Advertisement
Add Comment
Please, Sign In to add comment