title: show selected Firebase-object elements in a ListView
body: <p>I've a complex FirebaseDB Datamodell with ListAdapters for selected object-elements to be shown in a ListView in Android. Data is already on firebase.</p>
  
  <p>When adding the complete object I get an exception because relating Android-ListView-Elements are missing ... so I have to add only the required DB elements.</p>
  
  <p>I tried out a lot, but with result that Strings are mismatching with the items-ArrayList.</p>
  
  <p>Log-Message:
  FATAL EXCEPTION: main
                                                                             Process: com.connexibel.proficrmfree, PID: 2750
                                                                             java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.ArrayList.add(java.lang.Object)' on a null object reference
                                                                                 at com.connexibel.proficrmfree.lists.AccountsList$2.onChildAdded(AccountsList.java:257)</p>
  
  <p>Line 257 is the described line (I've deleted all my comment-lines for you).</p>
  
  <p>Has anyone the correct idea to get the right format???</p>
  
  <p><a href="https://i.stack.imgur.com/KO2fS.png" rel="nofollow noreferrer">Firebase</a></p>
  
  <pre><code>Android ListView.class:
  
  package com.connexibel.proficrmfree.lists;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.util.Log;
  import android.view.View;
  import android.view.Window;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  
  import com.connexibel.proficrmfree.R;
  import com.connexibel.proficrmfree.adapters.ListAdapterAccounts;
  import com.connexibel.proficrmfree.datamodell.DatamodellAccounts;
  import com.connexibel.proficrmfree.detailviews.AccountsDetail;
  import com.google.android.gms.ads.AdRequest;
  import com.google.android.gms.ads.AdView;
  import com.google.firebase.database.ChildEventListener;
  import com.google.firebase.database.DataSnapshot;
  import com.google.firebase.database.DatabaseError;
  import com.google.firebase.database.DatabaseReference;
  import com.google.firebase.database.FirebaseDatabase;
  
  import java.util.ArrayList;
  
  public class AccountsList extends AppCompatActivity {
  
      ArrayList&lt;DatamodellAccounts&gt; items;
      ListView listView;
      ArrayAdapter arrayAdapter;
  
      private AdView adViewTop;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.activity_accounts_list);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          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();
              }
          });
  
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
  
          FirebaseDatabase db = FirebaseDatabase.getInstance();
          final DatabaseReference refAccounts = db.getReference("Accounts");
          refAccounts.addChildEventListener(new ChildEventListener() {
  
              @Override
              public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                  DatamodellAccounts dm_accounts = dataSnapshot.getValue(DatamodellAccounts.class);
                  dm_accounts.setAccount_id(dataSnapshot.getKey());
  //this is the critical position!!! --&gt;
                  items.add(dm_accounts.getAccount_name1(), dm_accounts.getAccount_name2(), dm_accounts.getAccount_adress1(), dm_accounts.getAccount_zipcode(), dm_accounts.getAccount_city(), dm_accounts.getAccount_country(), dm_accounts.getAccount_internet());
                  listView = (ListView) findViewById(R.id.listViewAccountsPortrait);
                  arrayAdapter = new ListAdapterAccounts(getApplicationContext(), items);
                  listView.setAdapter(arrayAdapter);
                  listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
                      @Override
                      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                          Intent i = new Intent(getApplicationContext(), AccountsDetail.class);
                          i.putExtra("account_id", items.get(position).getAccount_id());
                          startActivity(i);
                      }
                  });
              }
  
              @Override
              public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                  DatamodellAccounts dm_accounts = dataSnapshot.getValue(DatamodellAccounts.class);
                  dm_accounts.setAccount_id(dataSnapshot.getKey());
                  items.add(dm_accounts);
                  listView = (ListView) findViewById(R.id.listViewAccountsPortrait);
                  arrayAdapter = new ListAdapterAccounts(getApplicationContext(), items);
                  listView.setAdapter(arrayAdapter);
                  listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
                      @Override
                      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                          Intent i = new Intent(getApplicationContext(), AccountsDetail.class);
                          i.putExtra("account_id", items.get(position).getAccount_id());
                          startActivity(i);
                      }
                  });
              }
  
              @Override
              public void onChildRemoved(DataSnapshot dataSnapshot) {
                  DatamodellAccounts dm_accounts = dataSnapshot.getValue(DatamodellAccounts.class);
                  dm_accounts.setAccount_id(dataSnapshot.getKey());
                  items.remove(dm_accounts);
                  listView = (ListView) findViewById(R.id.listViewAccountsPortrait);
                  arrayAdapter = new ListAdapterAccounts(getApplicationContext(), items);
                  listView.setAdapter(arrayAdapter);
                  listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
                      @Override
                      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                          Intent i = new Intent(getApplicationContext(), AccountsDetail.class);
                          i.putExtra("account_id", items.get(position).getAccount_id());
                          startActivity(i);
                      }
                  });
              }
  
              @Override
              public void onChildMoved(DataSnapshot dataSnapshot, String s) {
                  DatamodellAccounts dm_accounts = dataSnapshot.getValue(DatamodellAccounts.class);
                  dm_accounts.setAccount_id(dataSnapshot.getKey());
                  //der bestehenden Liste neu erzeugte Objekte hinzufügen
                  items.add(dm_accounts);
                  listView = (ListView) findViewById(R.id.listViewAccountsPortrait);
                  arrayAdapter = new ListAdapterAccounts(getApplicationContext(), items);
                  listView.setAdapter(arrayAdapter);
                  listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                      @Override
                      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                          Intent i = new Intent(getApplicationContext(), AccountsDetail.class);
                          i.putExtra("account_id", items.get(position).getAccount_id());
                          startActivity(i);
                      }
                  });
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
                  Log.i("Daten", databaseError.toString());
  
              }
          });
  
  
          adViewTop = (AdView) findViewById(R.id.adViewTop);
          AdRequest adRequest = new AdRequest.Builder()
                  .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                  .build();
          adViewTop.loadAd(adRequest);
      }
  }
  </code></pre>