how to enable firebase offline data and pass the data to recyclerview adapter?

I work on android chat app and it work fine until i added this line to myapplication classFirebaseDatabase.getInstance().setPersistenceEnabled(true); to enable getting offline users messages it cause my app to crash with this error message Failed to convert a value of type java.lang.String to long

and if i removed this line from myApplication class app work fine , i know it is because i get data in pojo class ,how to do that to get benefit of firebase offline capabilities and pass these data to recyclerview adapter my fetch message method

DatabasReference ref = FirebaseDatabase.getInstance().getreference().child("messages")
    private void fetchMessages() {
            if (mChildEventListener == null) {
                mChildEventListener = new ChildEventListener() {
                    public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {
                        if (snapshot.exists()) {
                            Messages messages = snapshot.getValue(Messages.class);
                            mRecyclerView.smoothScrollToPosition(messagesList.size() - 1);
                    public void onChildChanged(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {

My database structure

"Users": {
    "useId": {
      "name": m,
      "image": true
"useId": {
      "name": n,
      "image": true
"Messages" :{
   "mesageId" : {
      from: "MERjk5566699jjg"
      photoUrl : null
     seen :false

and message class

public class Messages {
    private String message,from ,photoUrl;
    private long date;
    private boolean seen;

    public Messages() {

    public Messages(String message, String from, String photoUrl, long date, boolean seen) {
        this.message = message;
        this.from = from;
        this.photoUrl = photoUrl; = date;
        this.seen = seen;


I answer my question to help anyone if he get an error like Failed to convert a value of type java.lang.String to long

when using FirebaseDatabase.getInstance().setPersistenceEnabled(true); the error occurred because I retrieve data like

Messages messages = snapshot.getValue(Messages.class);

it is not right to do that when using firebase offline ,the right way to retrieve every child like

String text = snapshot.child("message").getValue().toString;

and then create instance of your class and pass it to adapter

Source: stackoverflow