title: My android app stops when I try to traverse a map
body: <p>I'm creating an activity in my app that outputs the data in the database. 
  I have a map of products, and when I try to traverse to output the data the app stops. This is my code:</p>
  
  <pre><code>package com.axiobase.axiobaseapp;
  import android.content.Context;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Gravity;
  import android.view.View;
  import android.widget.Button;
  import android.widget.LinearLayout;
  import android.widget.TableRow;
  import android.widget.TextView;
  
  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 com.google.firebase.database.ValueEventListener;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  
  public class ManagersActivity extends AppCompatActivity {
  
  FirebaseDatabase database = FirebaseDatabase.getInstance();
  DatabaseReference myRef = database.getReference().child("PossibleSale");
  DatabaseReference reference = database.getReference().child("Equipment");
  List&lt;PossibleSale&gt; possibleSaleList = new ArrayList&lt;PossibleSale&gt;();
  List&lt;String&gt; possibleSalesStringList = new ArrayList&lt;String&gt;();
  PossibleSale possibleSale;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_managers);
  
      final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout1);
      final Context context = this;
  
      myRef.addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot snapshot) {
  
              for (DataSnapshot child : snapshot.getChildren()) {
                  Log.d("INPUT_INDICATORS", "Value is: " + child);
  
                  possibleSale = child.getValue(PossibleSale.class);
                  TextView textView1 = new TextView(context);
                  textView1.setText(child.getValue(PossibleSale.class).getCompany_name());
                  textView1.setPadding(50, 1, 1, 1);
                  textView1.setTextSize(20);
  
                  TextView textView2 = new TextView(context);
                  String state = new String();
                  state = "Estado de venta: ";
                  if (child.getValue(PossibleSale.class).getStatus() == 0){
                      state += "En Progreso";
                  }
                  else if (child.getValue(PossibleSale.class).getStatus() == 1){
                      state += "Vendida";
                  }
                  else if (child.getValue(PossibleSale.class).getStatus() == 2){
                      state += "Suspendida";
                  }
  
                  textView2.setText(state);
                  textView2.setPadding(100,1,1,1);
                  textView2.setTextSize(18);
  
                  double probab = child.getValue(PossibleSale.class).getProbability();
                  String probability = "Probabilidad  " + String.valueOf(probab);
                  TextView textView3 = new TextView(context);
                  textView3.setText(probability);
                  textView3.setPadding(100, 1, 1, 1);
                  textView3.setTextSize(18);
  
  
                  linearLayout.addView(textView1);
                  linearLayout.addView(textView2);
                  linearLayout.addView(textView3);
  
  
                  Map&lt;String, Integer&gt; products = child.getValue(PossibleSale.class).getProducts();
  
  
                  for (Map.Entry&lt;String, Integer&gt; entry : products.entrySet()){
                      TextView product = new TextView(context);
                      String key = entry.getKey();
                      Integer value = entry.getValue();
                      product.setText(key);
                      product.setTextSize(18);
                      product.setPadding(100, 1, 1, 1);
                      linearLayout.addView(product);
                  }
  
  
  
  
              }
  
          }
          @Override
          public void onCancelled(DatabaseError databaseError) {
              Log.w("INPUT_INDICATORS", "Failed to read value.", databaseError.toException());
          }
      });
  
  }
  
  
  }
  </code></pre>
  
  <p>The problem occurs in this for loop:</p>
  
  <pre><code>    Map&lt;String, Integer&gt; products =  child.getValue(PossibleSale.class).getProducts();
  
              for (Map.Entry&lt;String, Integer&gt; entry : products.entrySet()){
                  TextView product = new TextView(context);
                  String key = entry.getKey();
                  Integer value = entry.getValue();
                  product.setText(key);
                  product.setTextSize(18);
                  product.setPadding(100, 1, 1, 1);
                  linearLayout.addView(product);
              }
  </code></pre>
  
  <p>When I comment it the app works without problems. </p>
  
  <p>The error I'm getting is:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke interface method 
  'java.util.Set java.util.Map.entrySet()' on a null object reference
  </code></pre>
  
  <p>How can I fix this?</p>