title: Feed listview with Firebase Database using custom Adapters and Rows
body: <p>I know similar questions have been asked here before, but none of them seem to help me, so here I am, trying to retrieve the data from my firebase database: <img src="https://i.stack.imgur.com/kw30h.jpg" alt="firebase database"> in <code>ShiftInformation/1515547726961/PatientInformatin/5512552</code> and cast it to my listview in <strong>PatientActivity</strong>.</p>
  
  <pre><code>public class PatientActivity extends AppCompatActivity {
  
  private FirebaseAuth mAuth;
  private ListView listview;
  private List&lt;Patient&gt; patientList;
  DatabaseReference dref;
  ArrayList&lt;String&gt; list=new ArrayList&lt;&gt;();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_patient);
  
      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                      .setAction("Action", null).show();
          }
      });
  
      getPatientList();
      ListViewAdapter adapter=new ListViewAdapter(PatientActivity.this,R.layout.list_item,patientList);
      listview.setAdapter(adapter);
  
  
  }
  
  public List&lt;Patient&gt; getPatientList(){
      patientList = new ArrayList&lt;&gt;();
      mAuth = FirebaseAuth.getInstance();
      listview = (ListView) findViewById(R.id.myListView);
      FirebaseUser user = mAuth.getCurrentUser();
      final FirebaseDatabase database = FirebaseDatabase.getInstance();
      final DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
      DatabaseReference shiftRef = rootRef.child("UserInformation").child("Shift").child(user.getUid()).child("Shift");
      ValueEventListener eventListener = new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                  String ushift = dataSnapshot.getValue(String.class);
                  DatabaseReference PatientInfo = rootRef.child("ShiftInformation/" + ushift + "/PatientInformation");
  
                  final ListViewAdapter adapter = new ListViewAdapter(PatientActivity.this, R.layout.list_item, patientList);
                  PatientInfo.addChildEventListener(new ChildEventListener() {
                      @Override
                      public void onChildAdded(DataSnapshot dataSnapshot, String s) {
  
                         Patient patient = dataSnapshot.getValue(Patient.class);
                          String txtTitle = patient.getPatientName();
                          String txtLeito = patient.getPatientLeito();
                          list.add(new Patient(R.drawable.common_google_signin_btn_icon_dark, txtTitle, txtLeito));
                          adapter.notifyDataSetChanged();
                      }
  
                      @Override
                      public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                      }
  
                      @Override
                      public void onChildRemoved(DataSnapshot dataSnapshot) {
                          list.remove(dataSnapshot.getValue(String.class));
                          adapter.notifyDataSetChanged();
                      }
  
                      @Override
                      public void onChildMoved(DataSnapshot dataSnapshot, String s) {
                      }
  
                      @Override
                      public void onCancelled(DatabaseError databaseError) {
                      }
                  });
              }
  
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
          }
      };
      shiftRef.addListenerForSingleValueEvent(eventListener);
  
      return patientList;
  }
  </code></pre>
  
  <p>My <strong>ListViewAdapter.java</strong> looks like this:</p>
  
  <pre><code>public class ListViewAdapter extends ArrayAdapter&lt;Patient&gt; {
  
  public ListViewAdapter(@NonNull Context context, int resource, @NonNull List&lt;Patient&gt; objects) {
      super(context, resource, objects);
  }
  
  @NonNull
  @Override
  public View getView(int position, View convertView, ViewGroup parent){
      View v = convertView;
  
      if (v==null){
          LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          v = inflater.inflate(R.layout.list_item, null);
      }
  
      Patient patient = getItem(position);
      ImageView img = (ImageView) v.findViewById(R.id.imageView);
      TextView txtTitle = (TextView) v.findViewById(R.id.txtTitle);
      TextView txtLeito = (TextView) v.findViewById(R.id.txtLeito);
  
      //img.setImageResource(patient.getImageId());
      txtTitle.setText(patient.getPatientName());
      txtLeito.setText(patient.getPatientLeito());
  
      return v;
  
  }
  </code></pre>
  
  <p>and my <strong>Patient.java</strong> looks like this:
  public class Patient {</p>
  
  <pre><code>private int imageId;
  private String patientName;
  private String patientLeito;
  
  public Patient(int imageId, String patientName, String patientLeito){
      this.imageId = imageId;
      this.patientName = patientName;
      this.patientLeito = "Leito "+patientLeito;
  }
  
  /*    public int getImageId() {
      return imageId;
  }
  
  public void setImageId(int imageId) {
      this.imageId = imageId;
  }*/
  
  public String getPatientName() {
      return patientName;
  }
  
  public void setPatientName(String patientName) {
      this.patientName = patientName;
  }
  
  public String getPatientLeito() {
      return patientLeito;
  }
  
  public void setPatientLeito(String patientLeito) {
      this.patientLeito = patientLeito;
  }
  </code></pre>
  
  <p><strong>Question</strong>
  I have been getting the following error when compiling the app. Since my Patient can only return those strings, I cannot think of how to fix this!
  <img src="https://i.stack.imgur.com/tRrts.jpg" alt="error"></p>