-2

I am trying to retrieve time of my post from Firebase timestamp to the Feed activity through an Adapter and Viewholder. But, when I launch my app, it crashes. what could be the possible reason for that. Except that everything is working fine, I mean, Image Url and EditText data are retrieving safely. How to retrieve Time and display it in my feed. In the below code, the error is thrown at first line.

long millisecond = feed_list.get(position).getTimestamp().getTime();
String dateString = DateFormat.format("MM/dd/yyyy", new Date(millisecond)).toString();                       
holder.setTime(dateString);
Thrinadh Reddy
  • 525
  • 2
  • 8
  • 17

1 Answers1

0

You need to initialize your timestamp behind getTimestamp() or avoid the NullPointerException by checking the condition if it needs to be empty.

if (feed_list.get(position).getTimestamp() != null) {
    // do something
}

NullPointerException is thrown if you try to access a method - in your case getTime() on class Date which is null.

M_I
  • 132
  • 5