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)

これが私の完全なコードです。

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

私は自分のレベルで最善を尽くしましたが、エラーを特定できませんでした。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構造

{
  "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"
    }
  }
}
4

2 に答える 2

0

エラーメッセージには次のように記載されています。

認識されないフィールド "-880497298" (クラス Exam.vsrk.cleanvit.MapComponents.Maps.FireBaseUI.RemovedSpotItems)、無視可能としてマークされていません (4 つの既知のプロパティ: 、"status"、"owner"、"description"、"cleanedBy"])

JSON を Firebase から Java クラスに解析すると、Jackson はクラス内にstatusownerdescriptionおよびの 4 つのプロパティを見つけましcleanedByた。しかし、JSON で というフィールドが見つかりました-880497298。これをどう処理すればよいかわかりません。

この問題の原因は、アダプターへの間違った参照を渡していることのようです。コードからの関連スニペット:

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) {

ref.child("markers")そのため、アダプターを構築するときに最後の引数として渡す必要がある可能性が最も高いです。

これを修正した後でも、JSON がクラスと一致しないため、JSON-to-Java エラーが発生します。それを解決するために、この質問と回答を検討することをお勧めします: JSON を Firebase から Java オブジェクトに変換すると、「タイプへのバウンスに失敗しました」と表示されるのはなぜですか?

于 2016-01-02T15:39:58.823 に答える