如何从android中的firebase获取对象?
我有这样的用户类
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<User, UserHolder> adapter =
new FirebaseRecyclerAdapter<User, UserHolder>(
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
这然后它的工作正常,但如果火力点钥匙是
> c5755a68-69a7-4464-956e-c2f94d9b387d
这个唯一的ID然后它给出了一个错误
> com.firebase.client.FirebaseException: Failed to bounce to type
致命异常:主进程:in.rofr,PID:12399 com.firebase.client.FirebaseException:无法退出以在com.firebase.ui上的com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:183)上键入。 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)在android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:4611)在android.support.v7.widget.LinearLayoutManager $ LayoutState.next(LinearLayoutManager.java:1988)在android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.j AVA:1384)在android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1347)在android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)在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.widget.FrameLayout的android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)处的android.view.ViewGroup.layout(ViewGroup.java:5040)处的android.view.View.layout(View.java:15689) .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。在Android.widget.Lineout.layoutVertical(LinearLayout.java:1557)在android.widget.LinearLayout.onLayout(LinearLayout.java:1466)在android.view.View.layout(View.java: 15689)在android.view.View.layout(View.java:15689)处的android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1183)处的android.view.ViewGroup.layout(ViewGroup.java:5040) )在android.view.ViewGroup.layout(ViewGroup.java:5040)在android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)在android.widget.FrameLayout.onLayout(FrameLayout.java:514)在android.view .View.layout(View.java:15689)在android.view.ViewGroup.layout(ViewGroup.java:5040)在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)在android.widget.LinearLayout.layoutVertical( LinearLayout.java:1557)在android.view.View.layout(View.java:15689)android.view.ViewGroup.layout(ViewGroup.java:5040)android.widget.LinearLayout.onLayout(LinearLayout.java:1466) )在android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)在android.widget.FrameLayout.onLayout(FrameLayout.java:514)在android.view.View.layout(View.java:15689)在android.view .Group.layout(ViewGroup.java:5040)atroi d.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)在android.widget.LinearLayout.onLayout(LinearLayout.java:1466)在android.view.View .layout(View.java:15689)在android.view.ViewGroup.layout(ViewGroup.java:5040)在android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)在android.widget.FrameLayout.onLayout(的FrameLayout。在android.view.View.layout(View.java:15689)在android.view.ViewGroup.layout(ViewGroup.java:5040)在android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2116)在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编辑$ CallbackRecord.run(Choreographer.java:767)在android.view.Choreographer.doCallbacks(Choreographer.java:580)at android.view.Choreographer.doFrame(Choreographer.java:550)
什么是确切的问题 ,我没有得到任何人都可以帮助我?
提前致谢 !!!
尝试把@JsonIgnoreProperties(ignoreUnknown = true)放在类的顶部
@JsonIgnoreProperties(ignoreUnknown = true)
public class UserModel {
}
这可能会起作用,因为Firebase使用Jackson库来序列化/反序列化JSON,并且使用@JsonIgnoreProperties(ignoreUnknown = true)将忽略新的属性(未在类中声明的属性),如https://stackoverflow.com/所述一个/二百三十三万一千七百零五分之五百四十五万五千五百六十三
链接地址: http://www.djcxy.com/p/93149.html上一篇: how to get the object from firebase in android?
下一篇: java.lang.ClassCastException: com.parse.ParseObject cannot be cast to