2016-10-09 7 views
1

私はこのエラーをデバッグモードから受け取り、すべてがOKであると思われる理由はわかりません。データの一部がヌルではない、データの一部がヌルである、誰がなぜこれが起こるか知っていますか?ここで Android Firebaseの不思議なデータマッピング

enter image description here

は私Firebaseコードです:ここでは

mDatabase = FirebaseDatabase.getInstance(); 

    mReference = mDatabase.getReferenceFromUrl("https://basketball-training-app.firebaseio.com/article"); 

    mReference.addValueEventListener(new ValueEventListener() { 

    @Override 
    public void onDataChange(DataSnapshot dataSnapshot) { 

    articleModel = new ArrayList<>(); 
    for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) { 

     articleModel.add(postSnapshot.getValue(ArticleModel.class)); 
    } 



    adapter = new ArticleAdapter(getActivity().getApplicationContext(), R.layout.fragment_article_list_items, articleModel); 

    mListView.setAdapter(adapter); 
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
    @Override 
    public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { 
     Intent intent = new Intent(getActivity(), ArticleDetailsActivity.class); 
     final String postKey = mReference.getKey(); 
     intent.putExtra("post_key", postKey); 
     getActivity().startActivity(intent); 

    } 
}); 
    } 
     @Override 
     public void onCancelled(DatabaseError databaseError) { 
      throw databaseError.toException(); 
     } 
    }); 

あるFirebaseから自分のデータ:

[ { 
"body" : "Becoming a professional basketball player take ", 
"id" : "2", 
"photo" : "http://img.aws.livestrongcdn.com/ls-article-image-640/cme/cme_public_images/www_livestrong_com/photos.demandstudios.com/getty/article/108/235/489314780_XS.jpg", 
"published_date" : "2016-09-19", 
"thumb" : "http://img.aws.livestrongcdn.com/ls-article-image-640/cme/cme_public_images/www_livestrong_com/photos.demandstudios.com/getty/article/108/235/489314780_XS.jpg", 
"title" : "What Training Is Necessary to Become a Professional Basketball Player?", 
"video" : "" 
}, { 
"body" : "It's basketball; these are the best movies of", 
"id" : "0", 
"photo" : "http://images.contentful.com/7h71s48744nc/1w3KueQHLi2G0oyguoScQE/74af0a5222728503eff818ddcea6865e/coach-carter.jpg", 
"published_date" : "2016-09-19", 
"thumb" : "http://ecx.images-amazon.com/images/I/51FYWuWGPLL._SL160_.jpg", 
"title" : "Top Ten Greatest Basketball Movies", 
"video" : "" 
}, { 
"body" : "Basketball is a very popular sport played all around the ", 
"id" : "1", 
"photo" : "http://mba.org.mt/wp-content/uploads/2015/12/basketball-wallpaper-1280x768-1180x768.jpg", 
"published_date" : "2016-09-19", 
"thumb" : "http://mba.org.mt/wp-content/uploads/2015/12/basketball-wallpaper-1280x768-1180x768.jpg", 
    "title" : "Popularity of Basketball Around the World", 
"video" : "" 
} ] 

そしてここにあるモデル:

@PropertyName("thumb") 
private String thumb; 

@PropertyName("title") 
private String title; 

@PropertyName("published_date") 
private String published_date; 

@PropertyName("photo") 
private String photo; 

@PropertyName("body") 
private String body; 

@PropertyName("id") 
private String id; 

@PropertyName("video") 
private String video; 

public ArticleModel() { 
} 

public ArticleModel(String id, String title, String thumb, String published_date, String photo, String body, String video) { 
    this.id = id; 
    this.title = title; 
    this.thumb = thumb; 
    this.published_date = published_date; 
    this.photo = photo; 
    this.body = body; 
    this.video = video; 
} 



public String getBody() { 
    return body; 
} 

public void setBody(String body) { 
    this.body = body; 
} 

public String getId() { 
    return id; 
} 

public void setId(String id) { 
    this.id = id; 
} 

public String getThumb() { 
    return thumb; 
} 

public void setThumb(String thumb) { 
    this.thumb = thumb; 
} 

public String getTitle() { 
    return title; 
} 

public void setTitle(String title) { 
    this.title = title; 
} 

public String getData() { 
    return published_date; 
} 

public void setData(String published_date) { 
    this.published_date = published_date; 
} 

public String getImage() { 
    return photo; 
} 

public void setImage(String photo) { 
    this.photo = photo; 
} 

public String getVideoURI() { 
    return video; 
} 

public void setVideoURI(String video) { 
    this.video = video; 
} 

答えて

1

セッターgetterメソッドはプロパティ名と同じ名前にする必要があります。

これが問題を起こさないasynctaskのようそれは、奇妙である

public void setPhoto(String photo) { 
    this.photo = photo; 
} 

public String getPhoto() { 
    return photo; 
} 

public void setPublished_date(String published_date) { 
    this.published_date = published_date; 
} 

public String getPublished_date() { 
    return published_date; 
} 
+0

photopublished_dateのgetterメソッドとsetterメソッドを追加または変更...ありがとうございました! –

+0

@TomasMaksimaviciusあなたはasynctaskを使う必要はなく、ValueEventListenerは既に別のスレッドで実行されています。 :) – Wilik