3

So, im having no problems adding objects to the firebase database but when trying to retrieve the added objects from the database through the recyclerview using the Ui library i get the following error:

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

Here is the 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);

        }
    }
}

Here is the java model class:

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

and here is the object in the database im trying to retrieve :

Image

Debug trace

4
  • You skipped the most interesting part of the exception, which occurs after Caused by: com.fasterxml.jackson.databind.JsonMapping. But my initial guess is that Expense is defined inside another Java class, in which case you need to mark it static: public static class Expense Commented Apr 25, 2016 at 14:56
  • @FrankvanPuffelen I wish i had skipped it :-) but in actuality that is were it actually stops imgur.com/q373Q2l. I think this is because of this error when i run the app after a couple of seconds it force closes. Also Expense is its own class in my Model package. Commented Apr 25, 2016 at 15:38
  • Without seeing the full stack trace, the best I can tell you is to look for these: stackoverflow.com/questions/32108969/… Commented Apr 25, 2016 at 16:24
  • @FrankvanPuffelen I've added the debug trace at the bottom :-), Commented Apr 25, 2016 at 16:48

1 Answer 1

2

You're using a ListAdapter to show a single Expense. That means that each child of the ref is a single property amount, createdBy or name.

D/EventRaiser: Raising /Expense: CHILD_ADDED: { createdBy: anon }

D/EventRaiser: Raising /Expense: CHILD_ADDED: { name: BT bill }

The FirebaseRecyclerAdapter is made to work with a list of objects, i.e. a list of Expense objects. Once you create a list of expenses, it will work better.

Sign up to request clarification or add additional context in comments.

3 Comments

Case Closed :-) Problem solved. Thank you for taking your to helping me solve my problem. Very much appreciated.
I have check marked your answer but it wont let me up vote your post since i do not have a reputation of 15 yet :-( Again i would like to thank you for your time for helping me and have a good day .
@Nbacareerthrowaway, could you please explain what exactly you did to overcome this issue? I have exactly the same error, with similar class and FirebaseRecyclerAdapter as yours. If I do create a list of objects (as Frank pointed out), how/where should I use that list?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.