I have a RecyclerView that gets data from a Firebase database. When the RecyclerView reaches the end of the data feed the app crashes with following:
Logcat file:
 09-27 15:30:12.826 30184-30184/com.pctoolmanconsulting.trackmyweight E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                   Process: com.pctoolmanconsulting.trackmyweight, PID: 30184
                                                                                   java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.startsWith(java.lang.String)' on a null object reference
                                                                                       at com.pctoolmanconsulting.trackmyweight.ProgressViewHolder.bind(ProgressViewHolder.java:40)
                                                                                       at com.pctoolmanconsulting.trackmyweight.ProgressAdapter.onBindViewHolder(ProgressAdapter.java:41)
                                                                                       at com.pctoolmanconsulting.trackmyweight.ProgressAdapter.onBindViewHolder(ProgressAdapter.java:15)
I can not figure out where I am supposed to check for the null value. In the bind method of my ViewHolder class or in the adapter class.
Can someone help point me in the right direction?
Thanks.
My ViewHolder bind method:
public void bind (ImageProgress progress){
  name.setText(progress.name);
  if(progress.progressDetail.startsWith("https://firebasestorage.googleapis.com/") || progress.progressDetail.startsWith("content://")){
    progressDetailMessage.setVisibility(View.INVISIBLE);
    image.setVisibility(View.VISIBLE);
    Glide.with(activity).load(progress.progressDetail).fitCenter().into(image);
  } else {
     progressDetailMessage.setVisibility(View.VISIBLE);
     image.setVisibility(View.GONE);
     progressDetailMessage.setText(progress.progressDetail);
  }
}
adapter class:
public class ProgressAdapter extends RecyclerView.Adapter<ProgressViewHolder> {
  private static final String TAG ="ProgressAdapter";
  private final Activity activity;
  List<ImageProgress> progressDetails = new ArrayList<>();
  public ProgressAdapter(Activity activity){
    this.activity = activity;
  }
  public void addProgress(ImageProgress progress){
    progressDetails.add(progress);
    notifyItemInserted(progressDetails.size());
  }
  @Override
  public ProgressViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
    return new ProgressViewHolder(activity, activity.getLayoutInflater().inflate(android.R.layout.two_line_list_item,
            parent, false));
  }
  @Override
  public void onBindViewHolder(ProgressViewHolder holder, int position){
    holder.bind(progressDetails.get(position));
  }
  @Override
  public int getItemCount() {
    return progressDetails.size();
  }
}
 
     
    