- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试以 BusInformation.class
的形式从 firebase 实时数据库获取数据。但是我的应用程序在设置快照的类类型时崩溃了:ds.getValue(BusInformation.class);
我收到以下错误:
com.google.firebase.database.DatabaseException: Class com.example.muzammil.bustracking.app_classes.BusInformation does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.
at com.google.android.gms.internal.firebase_database.zzku.zza(Unknown Source)
at com.google.android.gms.internal.firebase_database.zzkt.zzb(Unknown Source)
at com.google.android.gms.internal.firebase_database.zzkt.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
以下是 BuInformation.java 类的代码:
public class BusInformation {
private String id, username,phone;
private LatLng position;
private String destination;
public BusInformation(String id, String username, String phone, String destination,LatLng position) {
this.id = id;
this.username = username;
this.phone = phone;
this.position = position;
this.destination = destination;
}
}
在 Firebase 数据库中,数据完全以这种形式存在。
从firebase获取数据的代码:
public void getUpdatesFromFirebase(DataSnapshot dataSnapshot){
for(DataSnapshot ds : dataSnapshot.getChildren()){
if(ds.exists()) {
busInfo = ds.getValue(BusInformation.class); //App crashes at this point
}
}
}
任何人请告诉我代码有什么问题......
最佳答案
BusInformation 未定义无参构造函数。
手动向其添加无参数构造函数:public BusInformation(){}
你的类应该是这样的:
public class BusInformation {
private String id, username,phone;
private LatLng position;
private String destination;
//no-argument constructor
public BusInformation(){}
public BusInformation(String id, String username, String phone, String destination,LatLng position) {
this.id = id;
this.username = username;
this.phone = phone;
this.position = position;
this.destination = destination;
}
}
关于java - datasnapshot.getvalue() 不起作用并导致应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52344088/
这是一个广泛的问题,涉及在 Firebase 数据上运行查询与不使用查询类访问数据之间的区别。 下面是一个查询的结构,取自文档并进行了一些缩减: DatabaseReference myRef = d
我已经阅读了有关此问题的几个问题和答案,但无法解决。 我正在使用 Ionic2,并且有一种方法可以从 Firebase 数据库 v3 中检索数据。 我不明白为什么我在执行 ionic serve 时会
这是错误: 有问题的小部件是:FutureBuilder 构建函数绝不能返回 null。 要返回导致建筑小部件填充可用空间的空白空间,请返回“Container()”。要返回占用尽可能少空间的空白空间
我的问题是我试图让 messageAdapter 在 MessageActvity 的 recycleView 上显示数据库中的消息,这是执行此操作的方法代码(简而言之): 案例1 private v
我正在使用 Android Studio 尝试使用 Firebase 数据库。我遇到了以下问题。我想为多个恐龙创建卡片(这些在 Db 中)。所以我尝试的是使用 Firebase 提供的“onChild
我正在接听this question然后我想到了这个新问题。 在那个问题中,我这样描述我的示例代码: boolean firstCallDone = false; boolean secondCall
DataSnapshot 始终与 firebase 监听器相关联,但我正在开发一个按时间查询整个数据库的应用程序,所以我认为我可以通过手动创建 DataSnapshot 实例来解决这个问题,但我找不到
我正在我的应用程序中实现 Firebase Recyclerview UI。我已经实现了一个 recyclerview 适配器,它显示了以下异常。以下是我的适配器代码: FirebaseRecycle
我正在尝试遍历联系人节点的子节点。 . 但是我的 ListArray contacts 仅部分填充。前两个条目按预期填充数组(来自 Logcat 的输出),但第三个条目未能填充数组。这是 MainAc
完成一个聊天应用程序并在这里研究了很多问题(发现 1 个让我步入正轨 setTextViewText not updating widget)正如您将从我的代码中看到的那样,我已经关注了那个问题,但是
我对 Java 没有太多经验。我不确定这个问题是否愚蠢,但我需要从 Firebase 实时数据库获取用户名并返回此名称作为此方法的结果。所以,我想出了如何获取这个值,但我不明白如何返回它作为这个方法的
我对 Java 没有太多经验。我不确定这个问题是否愚蠢,但我需要从 Firebase 实时数据库获取用户名并返回此名称作为此方法的结果。所以,我想出了如何获取这个值,但我不明白如何返回它作为这个方法的
这个问题已经有答案了: How can I serialize my User class for the Firebase Database and fix this error? (2 个回答)
我对 Java 没有太多经验。我不确定这个问题是否愚蠢,但我需要从 Firebase 实时数据库获取用户名并返回此名称作为此方法的结果。所以,我想出了如何获取这个值,但我不明白如何返回它作为这个方法的
我对 Java 没有太多经验。我不确定这个问题是否愚蠢,但我需要从 Firebase 实时数据库获取用户名并返回此名称作为此方法的结果。所以,我想出了如何获取这个值,但我不明白如何返回它作为这个方法的
我是 Firebase 数据库的新手,我正在按照 Google 文档从我的数据库中检索数据。 我有这样的结构: root/||--- 82JWZZZd***| || |--- profil
我对 Java 没有太多经验。我不确定这个问题是否愚蠢,但我需要从 Firebase 实时数据库获取用户名并返回此名称作为此方法的结果。所以,我想出了如何获取这个值,但我不明白如何返回它作为这个方法的
我对 Java 没有太多经验。我不确定这个问题是否愚蠢,但我需要从 Firebase 实时数据库获取用户名并返回此名称作为此方法的结果。所以,我想出了如何获取这个值,但我不明白如何返回它作为这个方法的
我对 Java 没有太多经验。我不确定这个问题是否愚蠢,但我需要从 Firebase 实时数据库获取用户名并返回此名称作为此方法的结果。所以,我想出了如何获取这个值,但我不明白如何返回它作为这个方法的
我对 Java 没有太多经验。我不确定这个问题是否愚蠢,但我需要从 Firebase 实时数据库获取用户名并返回此名称作为此方法的结果。所以,我想出了如何获取这个值,但我不明白如何返回它作为这个方法的
我是一名优秀的程序员,十分优秀!