1

When I use the User class, user name and password is getting saved in cloud firestore, but timestamp is null. Anyone can help on resolving this issue.

public class AccountFragment extends Fragment {

Timestamp timestamp;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

final User user = new User(timestamp);

public class User {

private String username;
private String password;
Timestamp timestamp;

public User() {
}

public User(String username, String password, Timestamp timestamp) {
    this.username = username;
    this.password = password;
    this.timestamp = timestamp;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public Timestamp getTimestamp() {
    return timestamp;
}

public void setTimestamp(Timestamp timestamp) {
    this.timestamp = timestamp;
}

}

Please help.

Sabir Syed
  • 422
  • 3
  • 19
  • 1
    what is your problem ? you need to be more explicit – Christophe Chenel Dec 04 '18 at 19:15
  • it seems that you never initialised the timestamp object. – Carlos Dec 04 '18 at 19:54
  • 2
    If you are looking to create an object where the current timestamp is stored when pushed, you need to be using [`ServerValue.TIMESTAMP`](https://firebase.google.com/docs/reference/js/firebase.database.ServerValue#.TIMESTAMP). Currently, you're just making a TimeStamp object and not initializing it, so it is `null`. – shriakhilc Dec 04 '18 at 20:30
  • 1
    Check **[this](https://stackoverflow.com/questions/43584244/how-to-save-the-current-date-time-when-i-add-new-value-to-firebase-realtime-data)** out. – Alex Mamo Dec 05 '18 at 08:15
  • anyone please help me... – Sabir Syed Dec 06 '18 at 09:30

1 Answers1

1

Yes, I got the solution. Actually, I forgot to initialize it. After adding the below line my problem resolved.

timestamp = Timestamp.now();
Sukhbir
  • 1,410
  • 14
  • 33
Sabir Syed
  • 422
  • 3
  • 19