title: How to get specific child from Firebase database
body: <p>I have the above hierarchy- 
  <a href="https://i.stack.imgur.com/SjVsG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SjVsG.jpg" alt="enter image description here"></a></p>
  
  <p>I want to get a reference to the objects that are underlined in red.</p>
  
  <p>This is my code:</p>
  
  <pre><code> mRootRefTravel = new Firebase("https://myfirebase.firebaseio.com/");
      mRootRefTravel.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              Log.v("START_TRAVEL", "data: " + dataSnapshot.getValue());
              if (dataSnapshot.exists()) {
                  for (DataSnapshot firstSnapShot : dataSnapshot.getChildren()) {
  
                      for (DataSnapshot secondSnapShot : firstSnapShot.getChildren()) {
                          Log.v("START_TRAVEL", "children: " + secondSnapShot.getValue());
                          Log.v("START_TRAVEL", "children: Trip: "+ secondSnapShot.child("Trip").getValue());
  
                          travel.setAccommodationCost((long) secondSnapShot.child("AccommodationCost").getValue());
                      }
                  }
  
              }
              adapterStartTravel = new AdapterStartTravel(list, getActivity());
              mRecyclerView.setAdapter(adapterStartTravel);
          }
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
  
          }
      });
  </code></pre>
  
  <p>This is my LOG:</p>
  
  <pre><code>08-27 08:11:34.661 5002-5002/com.amit.trawel V/START_TRAVEL: data: {Trip_0={Trip={TravelingExpenses=233, CarRent=78, PhoneCosts=130, NumOfTickets=3, NumOfCars=3, LodgingExpenses=986, TripId=1, Currency=shekel, AccommodationCost=16, FoodBudget=2100, NumOfRoom=244, NumOfPeople=3, AttractionsBudge=1100, OtherExpenses=555, FlightTicketTotalCost=500, ShoppingExpenses=200, NumOfDaysInsurance=569, LodgingBudget=1200, TotalTripSum=40000, ShoppingBudget=350, InsuranceCost=250, AttractionsExpenses=2, NumOfNightsAccommodation=2, TravelingBudget=470, NumOfDaysCarRent=1, OtherExpensesBudget=300, Destination=israel, FoodExpenses=5}}, Trip_1={Trip={TravelingExpenses=666, CarRent=60, PhoneCosts=100, NumOfTickets=4, NumOfCars=4, LodgingExpenses=78, TripId=2, Currency=dinar, AccommodationCost=40, FoodBudget=3000, NumOfRoom=44, NumOfPeople=2, AttractionsBudge=1500, OtherExpenses=555, FlightTicketTotalCost=400, ShoppingExpenses=300, NumOfDaysInsurance=77, LodgingBudget=1300, TotalTripSum=50000, ShoppingBudget=220, InsuranceCost=220, AttractionsExpenses=3, NumOfNightsAccommodation=3, TravelingBudget=500, NumOfDaysCarRent=2, OtherExpensesBudget=200, Destination=jordan, FoodExpenses=127}, Purchase_0={Lat=0.0, SumSpent=0, Lng=0.0, TripID=1, DBRowID=1}}}
  
  08-27 08:11:34.662 5002-5002/com.amit.trawel V/START_TRAVEL: children: {TravelingExpenses=233, CarRent=78, PhoneCosts=130, NumOfTickets=3, NumOfCars=3, LodgingExpenses=986, TripId=1, Currency=shekel, AccommodationCost=16, FoodBudget=2100, NumOfRoom=244, NumOfPeople=3, AttractionsBudge=1100, OtherExpenses=555, FlightTicketTotalCost=500, ShoppingExpenses=200, NumOfDaysInsurance=569, LodgingBudget=1200, TotalTripSum=40000, ShoppingBudget=350, InsuranceCost=250, AttractionsExpenses=2, NumOfNightsAccommodation=2, TravelingBudget=470, NumOfDaysCarRent=1, OtherExpensesBudget=300, Destination=israel, FoodExpenses=5}
  
  08-27 08:11:34.662 5002-5002/com.amit.trawel V/START_TRAVEL: children: Trip: null
  </code></pre>
  
  <p>And this is the EXCEPTION i`m getting- </p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
  </code></pre>
  
  <p>The exception is for this line- </p>
  
  <pre><code>travel.setAccommodationCost((long) secondSnapShot.child("AccommodationCost").getValue());
  </code></pre>
  
  <p>I want to be able to get to this child only after higher child was created. That`s why I cannot reference the final path as hard coded path, like that: </p>
  
  <pre><code> mRootRefTravel = new Firebase("https://myfirebase.firebaseio.com/Trip_0/Trip");
  </code></pre>