我正试图从我已经创建的firebase数据库中获得一个特定的值。我关注了这个youtube教程和另一个类似的问题,这与我试图实现的目标相当相关。
这就是我的Firebase数据库看起来像数据库树的样子
以下是我到目前为止所尝试的。现在我只尝试获得名称项
在Oncreate方法中:
final TextView nametext = (TextView)findViewById(R.id.name);
Firebase.setAndroidContext(this);
final Firebase ref = new Firebase("https://fir-with-maps.firebaseio.com/Group 2");
final List<PlumbersList> listofplumbers = new ArrayList<>();
ref.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
PlumbersList plumberslist = dataSnapshot.getValue(PlumbersList.class);
listofplumbers.add(plumberslist);
String name = plumberslist.Name;
nametext.setText(name);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
PlumberList类
public class PlumbersList {
String Name;
String Snippet;
String Lat;
String Long;
public PlumbersList() {
}
public PlumbersList(String name, String snippet, String lat, String aLong) {
Name = name;
Snippet = snippet;
Lat = lat;
Long = aLong;
}
public String getName() {
return Name;
}
public String getSnippet() {
return Snippet;
}
public String getLat() {
return Lat;
}
public String getLong() {
return Long;
}
应用程序几秒钟后崩溃。以下是错误logcat的外观
09-09 23:41:19.381 1375-1375/digiart.mapwithfirebase E/UncaughtException: com.firebase.client.FirebaseException: Failed to bounce to type
at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:183)
at digiart.mapwithfirebase.checkingfirebase$1.onChildAdded(checkingfirebase.java:36)
at com.firebase.client.core.ChildEventRegistration.fireEvent(ChildEventRegistration.java:48)
at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:210)
at android.app.ActivityThread.main(ActivityThread.java:5833)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1113)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879)
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "Snippet" (class digiart.mapwithfirebase.PlumbersList), not marked as ignorable (0 known properties: ])
at [Source: java.io.StringReader@297f6a4e; line: 1, column: 13] (through reference chain: digiart.mapwithfirebase.PlumbersList["Snippet"])
at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:555)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:708)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1160)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:315)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)
at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:181)
at digiart.mapwithfirebase.checkingfirebase$1.onChildAdded(checkingfirebase.java:36)
at com.firebase.client.core.ChildEventRegistration.fireEvent(ChildEventRegistration.java:48)
at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:210)
at android.app.ActivityThread.main(ActivityThread.java:5833)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1113)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879)
09-09 23:41:19.711 1375-1375/digiart.mapwithfirebase E/AndroidRuntime: FATAL EXCEPTION: main Process: digiart.mapwithfirebase, PID: 1375
com.firebase.client.FirebaseException: Failed to bounce to type
at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:183)
at digiart.mapwithfirebase.checkingfirebase$1.onChildAdded(checkingfirebase.java:36)
at com.firebase.client.core.ChildEventRegistration.fireEvent(ChildEventRegistration.java:48)
at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:210)
at android.app.ActivityThread.main(ActivityThread.java:5833)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1113)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879)
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "Snippet" (class digiart.mapwithfirebase.PlumbersList), not marked as ignorable (0 known properties: ])
at [Source: java.io.StringReader@297f6a4e; line: 1, column: 13] (through reference chain: digiart.mapwithfirebase.PlumbersList["Snippet"])
at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:555)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:708)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1160)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:315)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)
at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:181)
at digiart.mapwithfirebase.checkingfirebase$1.onChildAdded(checkingfirebase.java:36)
at com.firebase.client.core.ChildEventRegistration.fireEvent(ChildEventRegistration.java:48)
at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:210)
at android.app.ActivityThread.main(ActivityThread.java:5833)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1113)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879)
我是android编码的新手,所以我可能会在这里犯一些非常愚蠢的错误。
根据您的数据树,您正在从“组2”中读取,即您正在下载“组2”下的所有内容,包括“1”。你在这里试图实现什么是主要的问题。会不会有数据“2”、“3”、“4”等等?是否需要检索这些信息?
不,我只想从“1”中读取信息--基于您将textview设置为单个名称,我假设您只需要第一项。因此,您应该使用AddValueEventListener
,并直接从https://fir-with-maps.firebaseio.com/group2/1
读取
// add child "1"
ref.child("1").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
PlumbersList plumberslist = dataSnapshot.getValue(PlumbersList.class);
}
});
是的,我需要“第二组”下的一切--那么你只需要再深入一个层次。
ref.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
DataSnapshot childSnapshot = dataSnapshot.getValue(); // get the values of "1"
PlumbersList plumberslist = childSnapshot.getValue(PlumbersList.class);
listofplumbers.add(plumberslist);
String name = plumberslist.Name;
nametext.setText(name);
}
});
我试图从Firebase数据库中读取数据,我已经到处阅读和查找,但我已经走到了死胡同。 这就是我所做的一切。 依赖项: 实现'com.google.firebase: Firebase存储: 9.2.1' 实现'com。谷歌。firebase:firebase数据库:9.2。1' 实现'com。谷歌。firebase:firebase授权:9.2。1' 实现'com。谷歌。火基:火基核心:9.2。
问题内容: 我正在研究Firebase项目,我在其中将用户信息存储在表中。现在,我的要求是在表中显示所有用户。这是我的数据库快照 我可以使用从数据库中获取所有用户 上面的代码向我返回了包含bod,电子邮件,姓名,性别的用户数组。但是我只想获取电子邮件和用户名。 有没有一种方法只能从数据库中获取指定的字段? 问题答案: 读取节点时,必须检索其全部内容。因此,无法从读取路径时返回的数据中仅获取 特定
我需要在某个时间读取firebase数据库中的一个值。另外,即使数据库voteValue在以后的某个时候发生了变化,我也不希望读取值被更新。不过,如果它更容易,我想我会去它。 我的firebase数据库中有许多时隙--它们碰巧是以秒为单位的时间。我已经调用了这些时隙,我在每个时隙都有一个投票值。 所以在下面的例子中,假设时间是@11seconds。我想读到那个时段的投票值是8
我已经花了几个小时阅读产品分支中的0和1。请在Firebase数据库有经验的人帮助我:(
因此,我尝试拍摄数据库的快照,并添加带有子项的数组字符串中的项。 我的set和get java文件如下所示 但是,当我的程序到达dataQuery方法并尝试获取和设置名称和成分时,它会崩溃。有人能解释一下我做错了什么,以及是否有更好的方法来使用数据库快照来做到这一点吗? 进程:in.tvac.akshayejh.firebasesearch,PID:24798java.lang.NullPoint
任何帮助都将得到高度赞赏。求求你了。