2017-12-30 43 views
0

私はデータスナップショットで受け取ったすべての子を反復し、そのキーをマップに入れようとしています。以下のコードスニペットでは、データがマップに格納されている場所で実行が停止しているようです。Firebase上のすべての子を反復できません

 FirebaseDatabase.getInstance().getReference().child("Fixtures").addValueEventListener(new ValueEventListener() { 
     @Override 
     public void onDataChange(DataSnapshot snapshot) { 

      if (snapshot.exists()) { 

       long childcount = snapshot.getChildrenCount(); 

        for (DataSnapshot ds : snapshot.getChildren()) { 

         String currentuser = ds.getKey(); 
         List<UserFixtures> emptyList = new ArrayList<>(); 
         userPredictions.put(currentuser, emptyList); 

         childcount--; 

         if (childcount == 0) { 
          addFixturestoUserPredictions(); 
         } 

       } 
      } 
     } 
     @Override 
     public void onCancelled (DatabaseError error){ 

     } 
    }); 

したがって、3つの子がありますが、最初の繰り返しでは、map.putメソッドの後で実行が停止します。それはクラッシュしません、それはちょうど停止し、子どもに達することさえできません - ;私は何が起こっているのか分かりません。

スナップショットには、3つのすべての子とそのデータが含まれています。

このコードはGoogle App Engineにあります。

+0

あなたはログを共有することができますか?そして、なぜ空のリストをmap(List emptyList = new ArrayList <>(); userPredictions.put(currentuser、emptyList);)に追加していますか? – mark922

答えて

0

問題を解明しました。私は

Map<String, List<UserFixtures>> userPredictions 

としての私のリストを宣言していたが、私はされている必要があります

...

Map<String, List<UserFixtures>> userPredictions = new HashMap<>(); 
関連する問題