我正在尝试计算Java中的Firebase数据库中的所有值。但是它不起作用,我已经看过一些教程,但是还没有找到适合Java程序员的教程。
这是我的数据库:
Language
German
Message
-Jf6ShYy7niHrqg_x4Tc: "Tomorrow is very windy"
-Jf9v0xHAxINUUANrORU: "Today is very windy and rainy"
这是我的代码,请注意我尝试使用count max值的行:
Firebase f = new Firebase("https://myapp.firebaseio.com/Language/German/Message/");
f.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot snapshot) {
disp_msg = (TextView)findViewById(R.id.display_msg);
//disp_msg.setText(snapshot.getValue().toString());
Iterable<DataSnapshot> ds = snapshot.getChildren();
Iterator<DataSnapshot> ids = ds.iterator();
Map<String, Object> newPost = (Map<String, Object>) ids.next().getValue();
String msg = newPost.get("pubMsg").toString();
disp_msg.setText(msg.toString());
//The line below does not work getting the maximum values
int maxValueInMap=(Collections.max(newPost.values().toString()));
}
这是我在Collections的max函数中遇到的错误:
有谁知道如何用Java解决这个问题,谢谢。
最佳答案
在我的firebase子目录中运行时,找到了firebase函数:
long maxNum = snapshot.getChildrenCount();
int nums = (int)maxNum;
disp_msg.setText(msg.toString() + Integer.toString(nums));
关于java - 计算所有值Firebase Java API,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28159695/