Filter My RecyclerView

I’m trying to implement a search view for my hockey app this is the error I get.

java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String java.lang.String.toLowerCase()’ on a null object reference

Here is my code

public class HockeyAdapter extends RecyclerView.Adapter<HockeyAdapter.ViewHolder> implements Filterable {

private ArrayList playerList;
private List playerFull;
RequestOptions option;
private Context context;

public HockeyAdapter(ArrayList playerList, Context context) {
this.playerList = playerList;
this.context = context;
playerFull = new ArrayList<>(playerList);

//request glide
option = new RequestOptions().centerCrop().placeholder(R.drawable.loading_shape).error(R.drawable.loading_shape);


public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
view = layoutInflater.inflate(R.layout.hockey_cell, parent, false);
return new ViewHolder(view);

public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
final Player player = playerList.get(position);

//Load image with glide

//Load text;


public int getItemCount() {
return playerList.size();

public Filter getFilter() {
return exampleFilter;

private Filter exampleFilter = new Filter() {
protected FilterResults performFiltering(CharSequence constraint) {
ArrayList filteredList = new ArrayList<>();
if (constraint == null || constraint.length() == 0) {
} else {
String filteredPattern = constraint.toString().toLowerCase().trim();
for (Player item : playerFull) {
if (item.getName().toLowerCase().contains(filteredPattern)) {
FilterResults results = new FilterResults();
results.values = filteredList;
return results;

protected void publishResults(CharSequence constraint, FilterResults results) {
if (results.values != null) {
playerList.addAll((Collection<? extends Player>) results.values);

public class ViewHolder extends RecyclerView.ViewHolder {

public final ImageView pImg;
public final TextView name, position, team;

public ViewHolder(@NonNull View view) {
super(view); = view.findViewById(;
this.position = view.findViewById(;
this.pImg = view.findViewById(; = view.findViewById(;

I am trying this too. Waiting for the reply