我有这样的用户类
public class User{
int id;
String description;
String shortDescription;
String photo;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getShortDescription() {
return shortDescription;
}
public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
}
我正在使用FirebaseRecyclerAdapter获取存储在我的firebase上的用户,如下所示
FirebaseRecyclerAdapter adapter =
new FirebaseRecyclerAdapter(
User.class,
android.R.layout.two_line_list_item,
UserHolder.class,
mRef) {
@Override
protected void populateViewHolder(UserHolder userHolder, User u, int i) {
userHolder.mText.setText(u.getDescription());
}
};
但问题是用户对象的firebase密钥是什么时候
> -KDY9Pna7XqgFkyCHKFJ
然后它的工作正常,但如果firebase键是这样的
> c5755a68-69a7-4464-956e-c2f94d9b387d
这个唯一的ID然后它给出了一个错误
> com.firebase.client.FirebaseException: Failed to bounce to type
FATAL EXCEPTION: main
Process: in.rofr, PID: 12399
com.firebase.client.FirebaseException: Failed to bounce to type
at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:183)
at com.firebase.ui.FirebaseRecyclerAdapter.parseSnapshot(FirebaseRecyclerAdapter.java:161)
at com.firebase.ui.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:150)
at com.firebase.ui.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:190)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5465)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5498)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4735)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4611)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1988)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1384)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1347)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3026)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2903)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3277)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1183)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15689)
at android.view.ViewGroup.layout(ViewGroup.java:5040)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2116)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1873)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1084)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5990)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
什么是确切的问题,我没有得到任何人可以帮助我吗?
提前致谢 !!!
我能知道这行中的内容是userHolder.mText.setText(s.getDescription()); 我发现你在哪里宣布那个。
对不起它的u.getDescription()
仍然很少混淆,你能告诉关键。 调试时是firebase中的键还是Object的键?
Firebase Key ......
那么问题是JSON属性没有正确映射请看这个答案
如果没有JSON中的用户(如文本,请不要截图)和完整的堆栈跟踪(嵌套更有趣的错误消息),将无法提供帮助。 但@Kathi的答案确实是一个良好的开端。:-)
得到了解决方案......感谢您的详细解答。
尝试将@JsonIgnoreProperties(ignoreUnknown = true)放在类之上
@JsonIgnoreProperties(ignoreUnknown = true)
public class UserModel {
}
这可能有效,因为Firebase使用Jackson库来序列化/反序列化JSON,并且@JsonIgnoreProperties(ignoreUnknown = true)的使用是忽略新属性(类中未声明的属性),如此处所述https://stackoverflow.com/一个/二百三十三万一千七百零五分之五百四十五万五千五百六十三
这对我有用......谢谢
@KedarKalkote如果这个答案很有用,请单击左侧的upvote按钮。 如果它回答了您的问题,请单击复选标记以接受它。 这样,其他人就知道你已经(足够)得到了帮助。