Firebase数据库不显示数据到ListView,而是写入Firebase

时间:2019-02-16 15:51:31

标签: java android firebase firebase-realtime-database

我收到一个错误:

  

12378-12378 / info.androidhive.firebase W / ClassMapper:在类info.androidhive.firebase.Artist2上找不到artistName的设置器/字段

数据正在写入Firebase数据库,但未显示在<div class="bx-container"> <ul class="bx-slider"> <li> <img src="<?php echo get_bloginfo('template_directory'); ?>/assets/img/klbtg.jpg" alt="Project Image"/> </li> <li> <img src="<?php echo get_bloginfo('template_directory'); ?>/assets/img/bgld.jpg" alt="Project Image"/> </li> <li> <img src="<?php echo get_bloginfo('template_directory'); ?>/assets/img/klbth.jpg" alt="Project Image"/> </li> <li> <img src="<?php echo get_bloginfo('template_directory'); ?>/assets/img/bgle.jpg" alt="Project Image"/> </li> <li> <img src="<?php echo get_bloginfo('template_directory'); ?>/assets/img/klbtk.jpg" alt="Project Image"/> </li> <li> <img src="<?php echo get_bloginfo('template_directory'); ?>/assets/img/bglf.jpg" alt="Project Image"/> </li> </ul> <div class="bx-controls"> <div class="bx-counter"> 01 </div> <div class="bx-number"> 06 </div> <div class="bx-line-placeholder"> <div class="bx-line"> </div> </div> </div> </div> 中。

请在下面查看我的代码:

$(document).ready(function() {
    var bxSlider = $('.bx-slider').bxSlider({
        auto: true,
        mode: 'fade',
        pause: 5000,
        speed: 1000,
        controls: false,
        pager: false,
        preloadImages: 'visible',
        onSliderLoad: function() {
            $('.bx-container').css('visibility', 'visible');
            $('.bx-line').css('animation', 'mAnimationBxLine 5s ease-in-out infinite');
},
        onSlideAfter: function() {
            $('.bx-counter').text('0' + (bxSlider.getCurrentSlide() + 1));
        }
    });
});

}

包info.androidhive.firebase;

公共课程Artist2 {

ListView

}

公共类WishListActivity扩展了AppCompatActivity {

import android.widget.TextView;

import java.util.List;

public class ArtistList2 extends ArrayAdapter<Artist2> {

private Activity context; //context activity
private List<Artist2> artistList2; //list will store all the artists


//constructor parsing context and artist list
public ArtistList2(Activity context, List<Artist2> artistList2) {
    super(context, R.layout.list_layout2, artistList2); //passing context, layout file and the artist list
    this.context = context; //initialising variables
    this.artistList2 = artistList2;

}

@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) { //over ride get view method
    LayoutInflater inflater = context.getLayoutInflater(); //layout inflator object

    View listViewItem = inflater.inflate(R.layout.list_layout2,null,true); //creating list view object to inflate the xml list layout

    TextView textViewName2 = (TextView) listViewItem.findViewById(R.id.textViewName2); //create text view for the name
    TextView textViewGenre2 = (TextView) listViewItem.findViewById(R.id.textViewGenre2); //create text view for the genres

    Artist2 artist2 = artistList2.get(position);
    //Artist artist2 = artistList2.get(position); //gets the artists particular position

    textViewName2.setText(artist2.getArtistName2()); //set name value to the corresponding text view
    textViewGenre2.setText(artist2.getArtistGenre2()); //set genre value to the corresponding text view

    return listViewItem;

}

1 个答案:

答案 0 :(得分:0)

您遇到以下错误:

  

W / ClassMapper:在类info.androidhive.firebase.Artist2上找不到artistName的设置器/字段

因为反序列化时Firebase SDK在名为artistName的字段之后实际上不存在 的情况下正在查询数据库,因为在模型类中,所有文件都以{{1}结尾}(请参阅最后一个字符?)。要解决此问题,您可以更改模型类中的字段名称以匹配数据库中的字段名称,或者从服务器中删除实际数据,然后根据类中存在的字段添加新的字段。您还可以像这样在getter前面使用注释:

2