I have an app that was writing and reading perfectly to and from Firebase. I just added in a timestamp, which is converted from a string (see code below):
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date parsedDate = dateFormat.parse(eventDate);
Timestamp timestamp1 = new java.sql.Timestamp(parsedDate.getTime());
timestamp2 = timestamp1;
} catch(Exception e) {
}
My problem is that when I try to read from the database, I get the following error:
"com.google.firebase.database.DatabaseException: Class java.sql.Timestamp does not define a no-argument constructor."
This error comes when I try to read the data using a data snapshot. See my code below:
eventRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot eventSnapshot : dataSnapshot.getChildren()) {
Event event = eventSnapshot.getValue(Event.class);
events.add(event);
}
adapter.notifyDataSetChanged();
}
The error appears to be at the following line in this code:
Event event = eventSnapshot.getValue(Event.class);
Does anyone know how to solve this?
UPDATE: Code for my event class below:
import java.sql.Timestamp;
public class Event {
public String id;
public String name;
public String society;
public String date;
public String time;
public String location;
public String details;
public String nameLower;
public Timestamp timestamp;
public Event() {
}
//required default constructor
public Event(String id, String name, String society, String date, String time, String location, String details, String nameLower, Timestamp timestamp) {
this.id = id;
this.name = name;
this.society = society;
this.date = date;
this.time = time;
this.location = location;
this.details = details;
this.nameLower = nameLower;
this.timestamp = timestamp;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSociety() {
return society;
}
public void setSociety(String society) {
this.society = society;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getNameLower() {
return nameLower;
}
public void setNameLower(String nameLower) {
this.nameLower = nameLower;
}
public Timestamp getTimestamp() {
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp;
}
}