2
**I am trying to populate the firebase data via FirebaseRecyclerAdapter but i get  errors in log,
01-01 22:42:32.610  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Description: add
01-01 22:42:32.610  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Status: clean
01-01 22:42:32.610  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Description: ghffjggu
01-01 22:42:32.610  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Status: dirty
01-01 22:42:32.610  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Description: fhfhjhg
01-01 22:42:32.610  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Status: dirty
01-01 22:42:32.610  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Description: fg
01-01 22:42:32.610  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Status: dirty
01-01 22:42:32.610  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Description: ggg
01-01 22:42:32.610  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Status: dirty
01-01 22:42:32.610  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Description: add
01-01 22:42:32.611  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Status: dirty
01-01 22:42:32.611  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Description: .ark this
01-01 22:42:32.611  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Status: dirty
01-01 22:42:32.611  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Description: mark
01-01 22:42:32.611  25547-25547/exam.vsrk.cleanvit I/System.out﹕ Status: dirty
01-01 22:42:32.648  25547-25547/exam.vsrk.cleanvit D/AndroidRuntime﹕ Shutting down VM
01-01 22:42:32.650  25547-25547/exam.vsrk.cleanvit E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: exam.vsrk.cleanvit, PID: 25547
    com.firebase.client.FirebaseException: Failed to bounce to type
            at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:185)
            at com.firebase.ui.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:150)
            at com.firebase.ui.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:179)
            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.consumePendingUpdateOperations(RecyclerView.java:1445)
            at android.support.v7.widget.RecyclerView.access$400(RecyclerView.java:144)
            at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:282)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
            at android.view.Choreographer.doCallbacks(Choreographer.java:580)
            at android.view.Choreographer.doFrame(Choreographer.java:549)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
            at android.os.Handler.handleCallback(Handler.java:739)
            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.exc.UnrecognizedPropertyException: Unrecognized field "-880497298" (class exam.vsrk.cleanvit.MapComponents.Maps.FireBaseUI.RemovedSpotItems), not marked as ignorable (4 known properties: , "status", "owner", "description", "cleanedBy"])
            at [Source: java.io.StringReader@1026bfb7; line: 1, column: 16] (through reference chain: exam.vsrk.cleanvit.MapComponents.Maps.FireBaseUI.RemovedSpotItems["-880497298"])
            at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:555)
            at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:708)
            at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1160)
            at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:315)
            at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
            at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
            at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)
            at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:183)
            at com.firebase.ui.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:150)
            at com.firebase.ui.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:179)
            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.consumePendingUpdateOperations(RecyclerView.java:1445)
            at android.support.v7.widget.RecyclerView.access$400(RecyclerView.java:144)
            at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:282)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
            at android.view.Choreographer.doCallbacks(Choreographer.java:580)
            at android.view.Choreographer.doFrame(Choreographer.java:549)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
            at android.os.Handler.handleCallback(Handler.java:739)
            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)

Here's my complete code.

public class RemovedSpotsActivity extends AppCompatActivity {

  private FirebaseRecyclerAdapter mAdapter;
  List<RemovedSpotItems> removedSpots;


  @Override
  protected void onCreate(Bundle s) {

    super.onCreate(s);
    setContentView(R.layout.removed_spots_list);

    removedSpots=new ArrayList<>();

    Firebase.setAndroidContext(this);
    final Firebase ref = new Firebase(getResources().getString(R.string.firebase_url));
    RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler_view);
    recycler.setHasFixedSize(true);
    recycler.setLayoutManager(new LinearLayoutManager(this));
    String key=ref.child("markers").getKey();
    Log.v("KEY_ENTERED",key);
    ref.child("markers").addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
          Map<String, Object> newPost = (Map<String, Object>) dataSnapshot.getValue();
          System.out.println("Description: " + newPost.get("description"));
            System.out.println("Status: " + newPost.get("status"));
            RemovedSpotItems items = new RemovedSpotItems();

            items.setDescription((String) newPost.get("description"));
            items.setStatus((String) newPost.get("status"));
            removedSpots.add(items);
        }
        public void onChildChanged(DataSnapshot dataSnapshot, String s) { }
        public void onChildRemoved(DataSnapshot dataSnapshot) { }
        public void onChildMoved(DataSnapshot dataSnapshot, String s) { }
        public void onCancelled(FirebaseError firebaseError) { }
    });

    mAdapter = new FirebaseRecyclerAdapter<RemovedSpotItems, ReomvedSpotViewHolder>(RemovedSpotItems.class, R.layout.removed_spots_row, ReomvedSpotViewHolder.class,ref) {

        @Override
        protected void populateViewHolder(ReomvedSpotViewHolder viewHolder, RemovedSpotItems model, int position) {
            super.populateViewHolder(viewHolder, model, position);
            final int i = 0;
            Log.v("TAG","populating");
            RemovedSpotItems model1=removedSpots.get(i);

            viewHolder.description.setText(model1.getDescription());
            viewHolder.email.setText(model1.getStatus());
        }
    };

    recycler.setAdapter(mAdapter);
}

I have tried my level best but couldn't identify the error i think there is no problem in retrieving the data as it is correctly retrieved as we can see in the log there is some problem with FirebaseRecyclerAdapter.

RemovedSpotItems.java

public class RemovedSpotItems {
    public String description;
    public String cleanedBy;
    public String owner;
    public String status;

    public String getDescription()
    {
        return  description;
    }
    public void setDescription(String description)
    {
        this.description=description;        
    }
    public String getCleanedBy()
    {
        return cleanedBy;
    }
    public void setCleanedBy(String cleanedBy)
    {
        this.cleanedBy=cleanedBy;
    }
    public String getStatus()
    {
        return status;
    }
    public void setStatus(String status)
    {
        this.status=status;
    }
    public String getOwner() { return owner;}
    public  void setOwner(String owner)
    {
        this.owner=owner;
    }

}

JSON STRUCTURE

{
  "markers" : {
    "-341910319" : {
      "description" : "fhfhfhh",
      "latitude" : 26.207505661864655,
      "longitude" : 78.17407708615065,
      "owner" : "6b63df86-9d11-47f5-bac1-7150f9043016",
      "status" : "dirty"
    },
    "-101000882" : {
      "description" : "fifs",
      "latitude" : 26.207906640793592,
      "longitude" : 78.17450053989887,
      "owner" : "6b63df86-9d11-47f5-bac1-7150f9043016",
      "status" : "dirty"
    }
  },
  "users" : {
    "6b63df86-9d11-47f5-bac1-7150f9043016" : {
      "displayName" : "ramkishorevit@gmail.com",
      "provider" : "password"
    }
  }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Ramkishore V S
  • 124
  • 1
  • 8
  • Without seeing a sample of your JSON (as text please; screenshots of JSON are pretty useless) it's not possible to say what's causing this. We'll also need to see `RemovedSpotItems`, since that is what you're trying to map the JSON to. See http://stackoverflow.com/help/mcve how to make it easiest for us to help you. – Frank van Puffelen Jan 02 '16 at 01:37
  • I have added those can you please check now.. – Ramkishore V S Jan 02 '16 at 07:21

2 Answers2

0

The error message says:

Unrecognized field "-880497298" (class exam.vsrk.cleanvit.MapComponents.Maps.FireBaseUI.RemovedSpotItems), not marked as ignorable (4 known properties: , "status", "owner", "description", "cleanedBy"])

When parsing the JSON from Firebase to your Java class, Jackson found four properties in your class: status, owner, description and cleanedBy. But in the JSON it found a field called -880497298, which it doesn't know what to do with.

The cause of this problem seems to be that you're passing in the wrong reference to the adapter. The relevant snippets from your code:

final Firebase ref = new Firebase(getResources().getString(R.string.firebase_url));
...
String key=ref.child("markers").getKey();
...
mAdapter = new FirebaseRecyclerAdapter<RemovedSpotItems, ReomvedSpotViewHolder>(
    RemovedSpotItems.class, 
    R.layout.removed_spots_row, 
    ReomvedSpotViewHolder.class,
    ref) {

So most likely you need to pass in ref.child("markers") as the last argument when constructing your adapter.

After fixing this, you'll still get a JSON-to-Java error because your JSON doesn't match your class. I recommend studying this question and answer to solve that: Why do I get "Failed to bounce to type" when I turn JSON from Firebase into Java objects?

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
0

EDIT

Your RemovedSpotItems class needs a default constructor

there is a default (parameterless constructor) that is necessary for Firebase to be able to create a new instance of this class

public RemovedSpotItems() {}

Original with edit added

If you want to use your RemovedSpotItems class without needing all the properties in your JSON object you can use this:

import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 
...


 @JsonIgnoreProperties(ignoreUnknown=true)
 public class RemovedSpotItems { 
    ...
    //edit
    public RemovedSpotItems() {}
    ...
 }

Just make sure you're handling the ones you are using correctly.

The possible types returned by getValue() are Boolean, String, Long, Double, Map<String, Object>, and List<Object>. If no data exists at the location, the snapshot will return null.

ackushiw
  • 1,726
  • 2
  • 14
  • 15