2016-03-23 2 views
0

У меня есть пользовательский класс, как этоткак получить объект от firebase в android?

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; 
} 
} 

я выборки пользователя хранится на моем firebase используя FirebaseRecyclerAdapter вроде как показано ниже

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 

это, то его работает нормально но если firebase ключ, как

> c5755a68-69a7-4464-956e-c2f94d9b387d 

это уникальный идентификатор, то он дает ошибку

> com.firebase.client.FirebaseException: Failed to bounce to type 

FATAL ИСКЛЮЧЕНИЕ: главный процесса: в .rofr, PID: 12399 com.firebase.client.FirebaseException: Не удалось отскочить до типана com.firebase.client.DataSnapshot.getValue (DataSnapshot.java:183) в com.firebase.ui.FirebaseRecyclerAdapter.parseSnapshot (FirebaseRecyclerAdapter.java:161) в com.firebase.ui.FirebaseRecyclerAdapter.getItem (FirebaseRecyclerAdapter. Java: 150) на com.firebase.ui.FirebaseRecyclerAdapter.onBindViewHolder (FirebaseRecyclerAdapter.java:190) в android.support.v7.widget.RecyclerView $ Adapter.onBindViewHolder (RecyclerView.java:5465) в android.support. v7.widget.RecyclerView $ Adapter.bindViewHolder (RecyclerView.java:5498) на android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition (RecyclerView.java:4735) на android.suppor t.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.java: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) на android.support.v7.widget.RecyclerView.dispatchLayout (RecyclerView.java:2903) на android.support.v7.widget. RecyclerView.onLayout (Recycl erView.java:3277) на 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.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.widget.LinearLayout.onLayout (LinearLayout.java:1466) на android.view.View.layout (View.java:15689) на android.view.ViewGroup.layout (ViewGroup.java:5040) на android.support. v4.widget.DrawerLayout.onLayout (DrawerLayout.java:1183) на 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.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.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.java:514) на android.view.View.layout (View.java:15689) на android.view.ViewGroup.layout (ViewGroup.java:5040) на android.widget. LinearL ayout.setChildFrame (LinearLayout.java:1703) на android.widget.LinearLayout.layoutVertical (LinearLayout.java:1557) на android.widget.LinearLayout.onLayout (LinearLayout.java:1466) на android.view.View. макет (View.java:15689) на 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.view.ViewRootImpl.performLayout (ViewRootImpl. java: 2116) в android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:1873) в android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1084) в android.view.ViewRootImpl $ TraversalRunnable.run (ViewRootImpl.java:5990) на android.view.Choreographer $ CallbackRecord.run (Хореограф.java:767) на android.view.Choreographer.doCallbacks (Хореограф.java:580) на android.view.Choreographer.doFrame (Хореограф.java:550)

Что такое точный вопрос, я не получаю может кто помогите мне?

Заранее благодарен!

+0

Могу ли я узнать, что такое ** s ** в этой строке ** userHolder.mText.setText (s.getDescription()) ; ** i dnt найти, где вы объявили это. – Kathi

+0

извините его u.getDescription() –

+0

Все еще немного путайте, можете ли вы рассказать о ** ключе **. это ключ в firebase или ключе Object при отладке? – Kathi

ответ

2

Попробуйте положить @JsonIgnoreProperties (ignoreUnknown = TRUE) в верхней части класса, как этот

@JsonIgnoreProperties(ignoreUnknown = true) 
public class UserModel { 

} 

Это может работать, потому что Firebase использует библиотеку Джексона сериализация/deserialise JSON и использование @JsonIgnoreProperties (ignoreUnknown = истина) - игнорировать новые свойства (свойства, которые не объявлены в классе), как указано здесь https://stackoverflow.com/a/5455563/2331705

+0

Это работает для меня ... Спасибо –

+0

@KedarKalkote Если этот ответ был полезен, нажмите кнопку вверху слева от него. Если он ответил на ваш вопрос, нажмите галочку, чтобы принять его. Таким образом, другие знают, что вам (в достаточной мере) помогли. –

Смежные вопросы