0
firebaseデータベースにストロークされたカテゴリを表示しようとしています。次のようにRecyclerViewけどcom.google.firebase.database.DatabaseException:タイプjava.lang.Stringのオブジェクトをcom.csaminorproject.www.procompete.pojo.Categoryに変換できません。
私のPOJOこのエラーを取得するには、次のとおりです。
package com.csaminorproject.www.procompete.pojo;
import java.util.ArrayList;
import java.util.List;
public class Category {
List<String> categories = new ArrayList<>();
public Category() {
}
public Category(List<String> categories) {
this.categories = categories;
}
public List<String> getCategories() {
return categories;
}
public void setCategories(List<String> categories) {
this.categories = categories;
}
}
このRecyclerViewを持っている断片である:
public class SelectCategoryFragment extends Fragment {
static AppBarLayout appBar;
static LinearLayout selectCategoryFragment;
private static final String CATEGORIES = "categories";
private DatabaseReference mCategoryReference;
private FirebaseRecyclerAdapter mFirebaseAdapter;
private RecyclerView mCategoryRecyclerView;
public SelectCategoryFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_select_category, container, false);
appBar = (AppBarLayout) getActivity().findViewById(R.id.appBar);
selectCategoryFragment = (LinearLayout) getActivity().findViewById(R.id.selectCategoryFragment);
ImageView hideFilterFragment = (ImageView) view.findViewById(R.id.hideSelectCategoryFragment);
hideFilterFragment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
appBar.setVisibility(View.VISIBLE);
selectCategoryFragment.setVisibility(View.GONE);
}
});
mCategoryRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView_selectCategory);
mCategoryReference = FirebaseDatabase.getInstance().getReference().child(CATEGORIES);
Category c = new Category();
setUpFirebaseAdapter();
return view;
}
private void setUpFirebaseAdapter() {
mFirebaseAdapter = new FirebaseRecyclerAdapter<Category,
FirebaseCategoryViewHolder>(
Category.class,
R.layout.category_list_item,
FirebaseCategoryViewHolder.class,
mCategoryReference) {
@Override
protected void populateViewHolder(FirebaseCategoryViewHolder viewHolder,
Category model, int position) {
viewHolder.bindCategory(model);
}
};
mCategoryRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mCategoryRecyclerView.setAdapter(mFirebaseAdapter);
mCategoryRecyclerView.setHasFixedSize(true);
}
@Override
public void onDestroy() {
super.onDestroy();
mFirebaseAdapter.cleanup();
}
}
私のデータベースのスクリーンショットです。: