title: Populate the list view using specific data from the Firebase console
body: <p>I need help with displaying data from the firebase console. So the scene is that I have put some data in the console using a seperate class called "TicketSubmitted". I need to display some of the children of the data in a list view in the "MainActivity". The model class for the MainActivity is called "Ticket" and the adapter for the list view is called "TicketAdapter"</p>
  
  <p>the code for the MainActivity is:</p>
  
  <pre><code>package com.android.example.ithelpdesk;
  //imports
  
  public class MainActivity extends AppCompatActivity
      implements NavigationView.OnNavigationItemSelectedListener {
  
  DrawerLayout drawer;
  ActionBarDrawerToggle toggle;
  private FirebaseDatabase mFirebaseDatabase;
  private DatabaseReference mDatabaseReference;
  private ChildEventListener mChildEventListener;
  private FirebaseAuth mFirebaseAuth;
  private FirebaseAuth.AuthStateListener mAuthStateListener;
  public TicketAdapter adapter;
  private final static  int RC_SIGN_IN = 2;
  public String mUsername;
  private static final String TAG = "MainActivity";
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
  
      mFirebaseAuth = FirebaseAuth.getInstance();
      mFirebaseDatabase = FirebaseDatabase.getInstance();
      mDatabaseReference = FirebaseDatabase.getInstance().getReference();
  
      FirebaseUser user = mFirebaseAuth.getCurrentUser();
      mUsername = user.getUid();
  
      mAuthStateListener = new FirebaseAuth.AuthStateListener() {
          @Override
          public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
              FirebaseUser user = mFirebaseAuth.getCurrentUser();
              if (user != null) {
                  onSignedInInitialized(user.getDisplayName());
              } else {
                  onSignedOutCleanup();
                  startActivityForResult(
                          getInstance()
                                  .createSignInIntentBuilder()
                                  .setIsSmartLockEnabled(false)
                                  .setAvailableProviders(Arrays.asList(
                                          new AuthUI.IdpConfig.EmailBuilder().build(),
                                          new AuthUI.IdpConfig.GoogleBuilder().build()))
                                  .build(),
                          RC_SIGN_IN);
              }
          }
      };
  
      final ListView listView = (ListView) findViewById(R.id.lvTicket);
     final ArrayList&lt;String&gt; arrayOfTicket = new ArrayList&lt;&gt;()
      mDatabaseReference.addChildEventListener(new ChildEventListener() {
                                                   @Override
                                                   public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
  
                                                       Ticket ticket = (Ticket)dataSnapshot.getValue(Ticket.class);
                                                       adapter.add(ticket);
                                                   }
  
                                                   @Override
                                                   public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
  
                                                   }
  
                                                   @Override
                                                   public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
  
                                                   }
  
                                                   @Override
                                                   public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
  
                                                   }
  
                                                   @Override
                                                   public void onCancelled(@NonNull DatabaseError databaseError) {
  
                                                   }
                                               }
  
      );mDatabaseReference.
  
      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              FirebaseAuth.getInstance().signOut();
          }
      });
  
      drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      toggle = new ActionBarDrawerToggle(
              this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
      drawer.addDrawerListener(toggle);
      toggle.syncState();
  
      NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
      navigationView.setNavigationItemSelectedListener(this);
  
      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
  
              Intent intent = new Intent(view.getContext(), ComplaintDetail.class);
  
              startActivity(intent);
          }
  
      });
  
      final Button button = (Button) findViewById(R.id.complaintbutton);
      button.setOnClickListener(new View.OnClickListener() {
                                    public void onClick(View view) {
                                        Intent intent = new Intent(MainActivity.this, TicketCategory.class);
                                        startActivity(intent);
                                    }
                                }
      );
  
  }
  
  @Override
  protected void onPostCreate(Bundle savedInstanceState)
  {
      super.onPostCreate(savedInstanceState);
      toggle.syncState();
  }
  
  @Override
  public void onBackPressed() {
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      if (drawer.isDrawerOpen(GravityCompat.START)) {
          drawer.closeDrawer(GravityCompat.START);
      } else {
          super.onBackPressed();
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch(item.getItemId())
      {
          case R.id.action_settings:
          {
              AuthUI.getInstance().signOut(this);
              return true;
          }
          default:
              return super.onOptionsItemSelected(item);
      }
  }
  
  private void detachDatabaseReadListener()
  {
      if(mChildEventListener != null)
      {
          mDatabaseReference.removeEventListener(mChildEventListener);
          mChildEventListener = null;
      }
  }
  
  @Override
  protected void onResume()
  {
      super.onResume();
      mFirebaseAuth.addAuthStateListener(mAuthStateListener);
  }
  
  @Override
  protected void onPause()
  {
      super.onPause();
      mFirebaseAuth.removeAuthStateListener(mAuthStateListener);
  }
  
  private void onSignedInInitialized(String username)
  {
      mUsername = username;
     // attachDatabaseReadListener();
  }
  
  private void onSignedOutCleanup()
  {
      mUsername = null;
  
  }
  </code></pre>
  
  <p>The model class Ticket:</p>
  
  <pre><code>public class Ticket {
  public String TicketCategory;
   // public String Name;
  public String Subcategory;
  public String priority;
  private String status;
  private String comments;
  private String cannedReply;
  
  
  public Ticket (String TicketCategory, String Subcategory, String priority, String status, String comments, String cannedReply)
  {
      this.TicketCategory = TicketCategory;
   //   this.Name = Name;
      this.Subcategory = Subcategory;
      this.priority = priority;
      this.status = status;
      this.comments = comments;
      this.cannedReply = cannedReply;
  }
  
  
  public void setStatus(String status) {
      this.status = status;
  }
  
  public String getTicketCategory() {
      return TicketCategory;
  }
  
  //public String getName(){return Name;}
  
  public String getSubcategory() {
      return Subcategory;
  }
  
  public String getPriority() {
      return priority;
  }
  
  public String getComments() {
      return comments;
  }
  
  public void setComments(String comments) {
      this.comments = comments;
  }
  
  public String getCannedReply() {
      return cannedReply;
  }
  
  public void setCannedReply(String cannedReply) {
      this.cannedReply = cannedReply;
  }
  
  public String getStatus() {
     return status;
  
  }
  
  public static ArrayList&lt;Ticket&gt; getTicket()
  {
      ArrayList&lt;Ticket&gt; tickets = new ArrayList&lt;Ticket&gt;();
      return tickets;
  }}
  </code></pre>
  
  <p>The code for the adapter TicketAdapter is:</p>
  
  <pre><code>public class TicketAdapter extends ArrayAdapter&lt;Ticket&gt; {
  
  TicketAdapter(Context context, ArrayList&lt;Ticket&gt; tickets) {
      super(context, 0, tickets);
  }
  
  @SuppressLint("SetTextI18n")
  @NonNull
  @Override
  public View getView(int position, View convertView, @NonNull ViewGroup parent) {
      Ticket ticket = getItem(position);
      if (convertView == null) {
          convertView = LayoutInflater.from(getContext()).inflate(R.layout.tickets, parent, false);
      }
  
      TextView tvCategory = (TextView) convertView.findViewById(R.id.TicketCategory);
      TextView tvSubcategory = (TextView) convertView.findViewById(R.id.Subcategory);
      TextView tvPriority = (TextView) convertView.findViewById(R.id.priority);
  
  
      assert ticket != null;
      tvCategory.setText(ticket.TicketCategory);
      tvSubcategory.setText(ticket.Subcategory);
      tvPriority.setText(ticket.priority);
  
  
      return convertView;
  
  }}
  </code></pre>
  
  <p>I just want to display the TicketCategory, Subcategory and priority in a set manner in the list view but i am unable to do so. Also when I introduce a new childEventListener, i get this error and the app crashes:</p>
  
  <p><a href="https://i.stack.imgur.com/hsCbD.png" rel="nofollow noreferrer">Screenshot</a></p>
  
  <p>I am new at android programming so any input will be appreciated...</p>
  
  <p>thanks!!</p>