title: Save ArrayList in Firebase Database
body: <p>I am  building a mobile messaging application,</p>
  <p>I want to create a chat group where the user selects the members using a checkbox then save the identifiers of the selected users in a list which will be saved in the Firebase database,</p>
  <p>The problem that my application crash when I want to save the users to the database</p>
  <p>My logcat:</p>
  <blockquote>
  <p>com.google.firebase.database.DatabaseException: Expected a List while deserializing, but got a class java.lang.String</p>
  </blockquote>
  <p>Code:</p>
  <pre><code> private void CreateNewGroup(final String groupName) {
          groupNameRef = FirebaseDatabase.getInstance().getReference().child(&quot;Groups&quot;);
  
          DatabaseReference push = groupNameRef.push();
          String push_id = push.getKey();
  
  
          assert push_id != null;
          DatabaseReference ref = FirebaseDatabase.getInstance().getReference(&quot;Groups&quot;).child(push_id);
  
          Map&lt;String, String&gt; hasMap = new HashMap&lt;&gt;();
          hasMap.put(&quot;groupName&quot;, groupName);
          hasMap.put(&quot;Admin&quot;, firebaseUser.getUid());
          hasMap.put(&quot;members&quot;, &quot;&quot;);
          ref.setValue(hasMap).addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;Void&gt; task) {
                  Toast.makeText(SelectGroupActivity.this, &quot;Saved&quot; + groupName, Toast.LENGTH_SHORT).show();
              }
          });
  
  
          DatabaseReference ref2 = FirebaseDatabase.getInstance().getReference(&quot;Groups&quot; + &quot;/&quot; +
                  push_id + &quot;/&quot; + &quot;members&quot;);
  
          SharedPreferences myPref2 = SelectGroupActivity.this.getSharedPreferences(&quot;data2&quot;, Context.MODE_PRIVATE);
          Set&lt;String&gt; set1 = myPref2.getStringSet(&quot;key2&quot;, null);
  
          assert set1 != null;
          ArrayList&lt;String&gt; namesList = new ArrayList&lt;&gt;(set1);
          ref2.setValue(namesList).addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;Void&gt; task)
              {
                 if(task.isSuccessful())
              {
                  Toast.makeText(SelectGroupActivity.this, &quot;Success&quot;, Toast.LENGTH_SHORT).show();
              }
              }
          });
      }
  </code></pre>
  <p>And my Model class</p>
  <pre><code>import java.util.List;
  
  public class Groups
  {
      private String groupName;
      private List&lt;String&gt; members;
      private String Admin;
  
      public Groups() {}
  
      public Groups(String groupName, List&lt;String&gt; members, String Admin) {
          this.groupName = groupName;
          this.members = members;
          this.Admin = Admin;
      }
  
      public String getGroupName() {
          return groupName;
      }
  
      public void setGroupName(String groupName) {
          this.groupName = groupName;
      }
  
      public List&lt;String&gt; getMembers() {
          return members;
      }
  
      public void setMembers(List&lt;String&gt; members) {
          this.members = members;
      }
  
      public String getAdmin() {
          return Admin;
      }
      public void setAdmin(String admin) {
          Admin = admin;
      }
  }
  </code></pre>
  <p>Database:</p>
  <p><img src="https://i.stack.imgur.com/0FZmJ.png" alt="enter image description here" /></p>