Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Studio应用程序显示问题_Android_Firebase_Github - Fatal编程技术网

Android Studio应用程序显示问题

Android Studio应用程序显示问题,android,firebase,github,Android,Firebase,Github,我制作了一个应用程序,它将特定数据从数据库中提取到应用程序中,并在回收器视图中显示,但我有一个问题,我不知道如何解决,我很确定这与HomeFragment.java有关。请检查脚本末尾附近的多行注释。我将添加GitHub Repo,因为我认为这不是一个文件错误 对不起,你可能会遇到的痛苦和痛苦,因为你这么含糊不清,但我不知道如何更好地说 BlogRecyclerAdapter.Java: HomeFragment.Java: 谢谢大家! 回购: 指向HomeFragment.javaBlind的

我制作了一个应用程序,它将特定数据从数据库中提取到应用程序中,并在回收器视图中显示,但我有一个问题,我不知道如何解决,我很确定这与
HomeFragment.java
有关。请检查脚本末尾附近的多行注释。我将添加GitHub Repo,因为我认为这不是一个文件错误

对不起,你可能会遇到的痛苦和痛苦,因为你这么含糊不清,但我不知道如何更好地说

BlogRecyclerAdapter.Java:

HomeFragment.Java:

谢谢大家!

回购:

指向HomeFragment.javaBlind的路径:News/app/src/main/java/com/blindnews/kimh2/blindnews

编辑1:
为回收器适配器和HomeFragment上的代码添加了pastebin这并不是问题的完整解决方案,但在评论中我们解决了问题,即使用
Firestore
实时数据库获取数据

将此更改为片段-

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_home, container, false);

    blog_list = new ArrayList<>();
    blog_list_view = view.findViewById(R.id.blog_list_view);

    blogRecyclerAdapter = new BlogRecyclerAdapter(blog_list);
    blog_list_view.setLayoutManager(new LinearLayoutManager(container.getContext()));
    blog_list_view.setAdapter(blogRecyclerAdapter);

    firebaseFirestore = FirebaseFirestore.getInstance();
    firebaseFirestore.collection("articles").addSnapshotListener(new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
            for (DocumentChange doc : documentSnapshots.getDocumentChanges()) {
                if (doc.getType() == DocumentChange.Type.ADDED) {
                    BlogPost blogPost = doc.getDocument().toObject(BlogPost.class);
                    blog_list.add(blogPost);
                }
            }
            Log.d("HomeFragment", "onCreateView: " + blog_list.size());
            //Send updated list to adapter.
            blogRecyclerAdapter.updatePosts(blog_list);
        }
    });

    return view;
}
@覆盖
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图=充气机。充气(R.layout.fragment\u home,container,false);
blog_list=new ArrayList();
blog\u list\u view=view.findviewbyd(R.id.blog\u list\u view);
blogRecyclerAdapter=新的blogRecyclerAdapter(博客列表);
blog_list_view.setLayoutManager(新的LinearLayoutManager(container.getContext());
blog_list_view.setAdapter(blogRecyclerAdapter);
firebaseFirestore=firebaseFirestore.getInstance();
firebaseFirestore.collection(“articles”).addSnapshotListener(新的EventListener(){
@凌驾
public void OneEvent(QuerySnapshot文档快照,FireBaseFireStore异常e){
对于(DocumentChange文档:documentSnapshots.getDocumentChanges()){
if(doc.getType()==DocumentChange.Type.ADDED){
BlogPost BlogPost=doc.getDocument().toObject(BlogPost.class);
blog_list.add(blogPost);
}
}
Log.d(“HomeFragment”,“onCreateView:+blog_list.size());
//将更新的列表发送到适配器。
blogRecyclerAdapter.updatePosts(blog_列表);
}
});
返回视图;
}
适配器内的句柄更新列表-

public void updatePosts(List<BlogPost> blogPostList) {
    //if you want to update the whole list. If you want to append, List has addAll method I think and use it with notifyItemRangeInserted for better performance.
    this.blog_list = blogPostList;
    notifyDataSetChanged();
}
public void updatePosts(列表blogPostList){
//如果你想更新整个列表。如果你想追加,我认为列表有addAll方法,并将其与notifyItemRangeSerted一起使用,以获得更好的性能。
this.blog_list=blogPostList;
notifyDataSetChanged();
}

有什么问题;代码是否运行;logcat StackTrace是什么?当你运行应用程序时,它通常会在窗口底部的logcat中显示。我认为你的问题是,你需要在事件完成后设置blog_列表,然后调用notifydatasetchangesd()是的,但为此你需要添加Log.d(“标记”,“信息”);在您的codelogcat中,在更新适配器和检查列表的大小之前,了解是添加日志还是不添加日志会很有帮助。此日志将出现在logcat中,如果找不到,请使用标记进行搜索。已添加到解决方案中。如果删除if条件会怎么样
if(doc.getType()==DocumentChange.Type.ADDED)
。看起来您实际上并没有从
Firestore
获取文档。您是否在Firestore的
articles
集合中有文档?您是否可以从firebase控制台检查Firestore的
articles
集合中是否有文档?但这看起来像是
Realtime Database
并且您在代码中使用
Firestore
,它们是不同的。