这是逻辑错误,我在 Bundler could not find compatible versions for gem "activerecord":
In Gemfile:
annotate was resolved to 2.7.4, which depends on
activerecord (< 6.0, >= 3.2)
delayed_job_active_record was resolved to 4.1.3, which depends on
activerecord (< 5.3, >= 3.0)
kaminari was resolved to 1.1.1, which depends on
kaminari-activerecord (= 1.1.1) was resolved to 1.1.1, which depends on
activerecord
paper_trail was resolved to 10.2.0, which depends on
activerecord (< 6.1, >= 4.2)
rails (= 6.0.0.beta1) was resolved to 6.0.0.beta1, which depends on
activerecord (= 6.0.0.beta1)
rails-erd was resolved to 1.5.2, which depends on
activerecord (>= 3.2)
activeadmin-select2 was resolved to 0.1.8, which depends on
activeadmin was resolved to 1.4.3, which depends on
ransack (>= 1.8.7) was resolved to 2.1.1, which depends on
activerecord (>= 5.0)
seed_dump was resolved to 3.3.1, which depends on
activerecord (>= 4)
state_machines-activerecord was resolved to 0.5.2, which depends on
activerecord (< 6.0, >= 4.1)
textacular was resolved to 5.1.0, which depends on
activerecord (< 6.0, >= 5.0)
下检索7
儿童数,但是输出中只有四个儿童数
stocks
我使用OUTPUT: "4 Rubber Duck"
,并且输出不是全部的橡皮鸭。它应该总共textView.setText(allDuck " Rubber Duck");
个输出而不是四个。这是有问题的数据结构和代码,但我不知道问题出在哪里,能否请您帮我找到逻辑错误:我认为,firebase混淆了我的uid的读取,
7
。
Database
DuckCompany
SALES
WireHouse
Inventory
RubberDUCK
DuckID
axRGznal3nkhxsDax // this is uid
stocks
-LEeeeeeeeeeeeeeeee // this is id
redValue:"71"
-LFffffffffffffffff
redValue:"71"
-LGggggggggggggggg
redValue:"71"
cpsGGGGNxQQQOWqh
stocks
-LAaaaaaaaaaaaaaa
redValue:"71"
-LBbbbbbbbbbbbbbb
redValue:"71"
-LCccccccccccccc
redValue:"71"
-LDddddddddddddd
redValue:"71"
答案 0 :(得分:1)
您要遍历DuckID
下的所有(2)键,并为每个键获取stock
下的子项数量,但是您并没有在任何地方添加这些数量,只是覆盖了以前的值。
尝试以下方法:
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
int allDuck = 0;
for (DataSnapshot uids : dataSnapshot.child("DuckID").getChildren()) {
String uidKeys = uids.getKey();
if (uidKeys != null) {
allDuck += (int) dataSnapshot.child("DuckID").child(uidKeys).child("stocks").getChildrenCount();
}
}
textView.setText(allDuck " Rubber Duck");
}