title: for Loop impeding me from retrieving data from Database?
body: <p>Trying to retrieve data from Firebase to populate the screen with the user's <code>myID</code>, <code>userID</code>, and <code>imageURL</code> that's unique for each user. I have the following method <code>readMessage();</code> which is what retrieves that information from the database, but it isn't working properly. </p>
  
  <p>This is what the <strong>Logcat</strong> tells me <code>Can't convert object of type java.lang.String to type com.e.chatapp.Model.Chat</code>.</p>
  
  <p>At first I tried to get rid of the <code>for Loop</code> because in the past that made it work fine, but this time it hasn't helped. Can someone indicate what the error is in my code?</p>
  
  <p>Problem is the <code>if</code> statement.</p>
  
  <p>Below you have my <code>MessageActivity.java</code> and Model class <code>Chat.java</code>. </p>
  
  <p><a href="https://i.stack.imgur.com/mm7mq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mm7mq.png" alt="enter image description here"></a></p>
  
  <p><strong>MessageActivity.java</strong></p>
  
  <pre><code>private void sendMessage(String sender, String receiver, String message) {
  
      DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
  
      HashMap&lt;String, Object&gt; hashMap = new HashMap&lt;&gt;();
      hashMap.put("sender", sender);
      hashMap.put("receiver", receiver);
      hashMap.put("message", message);
  
      reference.child("Chats").child(mFirebaseUser.getUid()).setValue(hashMap);
  }
  
  private void readMessage(final String myID, final String userID, final String imageURL) {
      mChats = new ArrayList&lt;&gt;();
  
      mReference = FirebaseDatabase.getInstance().getReference("Chats");
      mReference.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              mChats.clear();
              for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                  Chat chat = snapshot.getValue(Chat.class);
                  if (chat.getReceiver().equals(myID) &amp;&amp; chat.getSender().equals(userID) ||
                          chat.getReceiver().equals(userID) &amp;&amp; chat.getSender().equals(myID)) {
                      mChats.add(chat);
                  }
  
                  mMessageAdapter = new MessageAdapter(MessageActivity.this, mChats, imageURL);
                  mRecyclerView.setAdapter(mMessageAdapter);
              }
          }
  
          @Override
          public void onCancelled(@NonNull DatabaseError databaseError) {
  
          }
      });
  }
  </code></pre>
  
  <p><strong>Also tried it like this</strong></p>
  
  <pre><code> private void readMessage(final String myID, final String userID, final String imageURL) {
          mChats = new ArrayList&lt;&gt;();
  
          mReference = FirebaseDatabase.getInstance().getReference("Chats");
          mReference.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                  mChats.clear();
                  for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                      Chat chat = snapshot.getValue(Chat.class);
                      if (chat.getReceiver().equals(myID) &amp;&amp; chat.getSender().equals(userID) ||
                              chat.getReceiver().equals(userID) &amp;&amp; chat.getSender().equals(myID)) {
                          mChats.add(chat);
                      }
  
                      mMessageAdapter = new MessageAdapter(MessageActivity.this, mChats, imageURL);
                      mRecyclerView.setAdapter(mMessageAdapter);
                  }
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
  
              }
          });
      }
  </code></pre>
  
  <p><strong>Chat.java</strong></p>
  
  <pre><code>public class Chat {
  
  private String sender;
  private String receiver;
  private String message;
  
  public Chat(String sender, String receiver, String message) {
      this.sender = sender;
      this.receiver = receiver;
      this.message = message;
  }
  
  public Chat() {
  }
  
  public String getSender() {
      return sender;
  }
  
  public void setSender(String sender) {
      this.sender = sender;
  }
  
  public String getReceiver() {
      return receiver;
  }
  
  public void setReceiver(String receiver) {
      this.receiver = receiver;
  }
  
  public String getMessage() {
      return message;
  }
  
  public void setMessage(String message) {
      this.message = message;
  }
  </code></pre>
  
  <p>}</p>