3

そのため、オブジェクトをfirebaseデータベースに追加するのに問題はありませんが、Uiライブラリを使用してrecyclerviewを介してデータベースから追​​加されたオブジェクトを取得しようとすると、次のエラーが発生します:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: smarthousebillsplitter, PID: 900
com.firebase.client.FirebaseException: Failed to bounce to type
    at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:185)
    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:5217)
    at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5250)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4487)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
    at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
    at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
    at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
    at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
    at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2900)
    at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071)
    at android.view.View.layout(View.java:15689)
    at android.view.ViewGroup.layout(ViewGroup.java:5040)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
    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)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
    at android.os.Handler.handleCallback(Handler.java:746)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5343)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
 Caused by: com.fasterxml.jackson.databind.JsonMappin

ここに recyclerview があります:

 public class ExpenseFragment extends Fragment  {
    private RecyclerView ExpenseRecyclerView;
    Firebase ExpenseRef = new Firebase(Constants.Firebase_URL).child("Expense");

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
        Firebase.setAndroidContext(getActivity());
    }

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_expense , container, false);
        ExpenseRecyclerView = (RecyclerView) view.findViewById(R.id.Expense_Recycler_View);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
        ExpenseRecyclerView.setLayoutManager(layoutManager);

             FirebaseRecyclerAdapter<Expense,ExpenseHolder> mRecyclerAdapter = new FirebaseRecyclerAdapter<Expense, ExpenseHolder>(Expense.class ,
                R.layout.custom_expense_row_layout,ExpenseHolder.class, ExpenseRef ) {
            @Override
            protected void populateViewHolder(ExpenseHolder expenseHolder, Expense expense, int i) {
                expenseHolder.nameTextView.setText(expense.getName());
                expenseHolder.amountTextView.setText(expense.getAmount());
               expenseHolder.createdByTextView.setText(expense.getCreatedBy());
                expenseHolder.shoppingImageView.setImageResource(R.drawable.shopping);
            }
        };

        ExpenseRecyclerView.setAdapter(mRecyclerAdapter); 
        return view;
    }

    public static class ExpenseHolder extends RecyclerView.ViewHolder {
      private TextView nameTextView;
        private TextView amountTextView;
        private TextView createdByTextView;
        private ImageView shoppingImageView;

        public ExpenseHolder(View itemView) {
            super(itemView);

            nameTextView = (TextView) itemView.findViewById(R.id.name);
            amountTextView = (TextView) itemView.findViewById(R.id.amount);
            createdByTextView = (TextView) itemView.findViewById(R.id.CreatedBy);
            shoppingImageView = (ImageView) itemView.findViewById(R.id.ExpenseImage);

        }
    }
}

Java モデル クラスは次のとおりです。

public class Expense {

    private String amount;
    private String createdBy;

    private String name;


    public Expense() {
    }

    public Expense(String amount, String createdBy, String name) {

        this.amount = amount;
        this.createdBy = createdBy;
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public String getAmount() {
        return amount;
    }

    public String getCreatedBy() {
        return createdBy;
    }
}

取得しようとしているデータベース内のオブジェクトは次のとおりです。

画像

デバッグ トレース

4

1 に答える 1

2

ListAdapter を使用して単一のExpense. つまり、ref の各子は単一のプロパティamountcreatedByまたはname.

D/EventRaiser: 調達 /Expense: CHILD_ADDED: { createdBy: anon }

D/EventRaiser: 調達 /Expense: CHILD_ADDED: { name: BT bill }

FirebaseRecyclerAdapter、オブジェクトのリスト、つまりオブジェクトのリストで動作するように作られていExpenseます。経費のリストを作成すると、より効果的になります。

于 2016-04-25T19:02:22.407 に答える