如何解決在firebase中的類com.hello.writer.postAdapter.PostGeter上找不到67903的setter/field

當(dāng)我想從ModelView類中的Firebase和SetValue恢復(fù)數(shù)據(jù)時(shí),會(huì)收到警告。我檢查數(shù)據(jù)庫和ModelView類中的所有數(shù)據(jù)。ModelView字符串名稱的鍵名是相同的,并且我在類中創(chuàng)建了setter方法。我不明白問題出在哪里。

我的ModelView類代碼:

public class PostGeter {
    private String body;
    private String date;
    private String id;
    private String image;
    private String reaction;
    private String status;
    private String title;
    private String userId;

    public PostGeter() {}

    public PostGeter(String body, String date, String id, String image, String reaction, String status, String title, String userId) {
        this.body = body;
        this.date = date;
        this.id = id;
        this.image = image;
        this.reaction = reaction;
        this.status = status;
        this.title = title;
        this.userId = userId;
    }

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

    public void setDate(String date) {
        this.date = date;
    }

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

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

    public void setReaction(String reaction) {
        this.reaction = reaction;
    }

    public void setStatus(String status) {
        this.status = status;
    }

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

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getBody() {
        return body;
    }

    public String getDate() {
        return date;
    }

    public String getId() {
        return id;
    }

    public String getImage() {
        return image;
    }

    public String getReaction() {
        return reaction;
    }

    public String getStatus() {
        return status;
    }

    public String getTitle() {
        return title;
    }

    public String getUserId() {
        return userId;
    }

我的適配器類:

public class postAdapter extends RecyclerView.Adapter<postAdapter.ViewHolder> {

    Context context;
    ArrayList<PostGeter> list;

    public postAdapter(Context context, ArrayList<PostGeter> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public postAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.post_content_view, parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull postAdapter.ViewHolder holder, int position) {
        PostGeter geter = list.get(position);
        holder.title.setText(geter.getTitle());
        holder.content.setText(geter.getBody());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        ImageView img; TextView title,content;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.postImageView);
            title = itemView.findViewById(R.id.post_view_title);
            content = itemView.findViewById(R.id.post_view_content);
        }
    }
}

我的firebase Data調(diào)用方法:

RecyclerView recyclerView = binding.postView;
        recyclerView.setHasFixedSize(true);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(manager);
        ArrayList list = new ArrayList<>();
        postAdapter customAdapter = new postAdapter(getContext(), list);
        recyclerView.setAdapter(customAdapter);

        database = FirebaseDatabase.getInstance();

        reference = database.getReference().child("posts");
        reference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                for (DataSnapshot ds : snapshot.getChildren()){
                    for (DataSnapshot data : ds.getChildren()){
                            System.out.println(data);
                            PostGeter msg = ds.getValue(PostGeter.class);
                            list.add( msg);

                    }
                }
            }

            @Override
            public void onCancelled(@NonNull DatabaseError error) {
                throw error.toException();

            }
        });

my log:

I/zygote64: After code cache collection, code=61KB, data=59KB
I/zygote64: Increasing code cache capacity to 256KB
D/FA: Application going to the background
I/System.out: DataSnapshot { key = 10843, value = {body=fasiaufsuie, title=ddddj} }
W/ClassMapper: No setter/field for 10843 found on class com.hello.writer.postAdapter.PostGeter
W/ClassMapper: No setter/field for 67903 found on class com.hello.writer.postAdapter.PostGeter
I/System.out: DataSnapshot { key = 67903, value = {date=06.03.2023, image=https://firebasestorage.googleapis.com/v0/b/hello-writer-2db52.appspot.com/o/posts%2FuserId%2F67903?alt=media&token=5bc42574-fe50-424a-8e74-af7aae7e33d0, reaction=0, id=67903, body=jgugjvvhv, title=vhhvvhuv, userId=user, status=approved} }
W/ClassMapper: No setter/field for 10843 found on class com.hello.writer.postAdapter.PostGeter
W/ClassMapper: No setter/field for 67903 found on class com.hello.writer.postAdapter.PostGeter
V/FA: Inactivity, disconnecting from the service
I/System.out: DataSnapshot { key = 67903, value = {date=06.03.2023, image=https://firebasestorage.googleapis.com/v0/b/hello-writer-2db52.appspot.com/o/posts%2FuserId%2F67903?alt=media&token=5bc42574-fe50-424a-8e74-af7aae7e33d0, reaction=0, id=67903, body=jgugjvvhv, title=vhhvvhuv, userId=user, status=approved} }
W/ClassMapper: No setter/field for 67903 found on class com.hello.writer.postAdapter.PostGeter

我想在recyclerView中顯示數(shù)據(jù)。我的數(shù)據(jù)庫JSON鏈接在這里:

我的數(shù)據(jù)庫json

? 最佳回答:

您將收到以下警告:

W/ClassMapper:在類com.hello.writer.postAdapter.PostGeter上找不到67903的setter/field

因?yàn)槟噲D使用以下代碼行將鍵轉(zhuǎn)換為PostGeter類型的對(duì)象:

PostGeter msg = ds.getValue(PostGeter.class);

要解決此問題,必須使用正確的DataSnapshot對(duì)象。因此,請(qǐng)將上述代碼行更改為:

PostGeter msg = data.getValue(PostGeter.class);
//              👆
主站蜘蛛池模板: 国产精品一区二区久久沈樵| 精品乱人伦一区二区| 中文字幕精品无码一区二区三区 | 中文字幕一区二区区免| 国产伦精品一区二区三区免费下载 | 无码毛片一区二区三区视频免费播放 | 国产91久久精品一区二区| 人妻免费一区二区三区最新| 久久精品国产一区二区三区不卡| 国产一区二区三区高清视频 | 久久久综合亚洲色一区二区三区 | 肉色超薄丝袜脚交一区二区| 亚洲国产日韩在线一区| 一区二区三区亚洲| 亚洲乱码一区av春药高潮| 一区二区三区国产| AV怡红院一区二区三区| 亚洲一区免费观看| 美女啪啪一区二区三区| 无码国产精品一区二区免费式影视| av无码免费一区二区三区| 日韩人妻不卡一区二区三区| 久久99国产精一区二区三区| 亚洲一区AV无码少妇电影☆| 国模无码人体一区二区| 免费萌白酱国产一区二区三区| 丝袜无码一区二区三区| 国产综合无码一区二区辣椒| 日韩免费观看一区| 成人免费一区二区三区| 激情内射日本一区二区三区| 国产在线精品一区二区夜色| 亚洲无线码一区二区三区| 久久国产视频一区| 精品欧洲AV无码一区二区男男| 亚洲日韩AV一区二区三区中文| 日本丰满少妇一区二区三区 | 日韩精品人妻一区二区三区四区 | 免费播放一区二区三区| 亚洲一区中文字幕在线观看| 亚洲av无码一区二区三区在线播放|