Java 显示用户拇指和用户名的Android应用程序回收器视图存在问题

Java 显示用户拇指和用户名的Android应用程序回收器视图存在问题,java,android,firebase,android-recyclerview,Java,Android,Firebase,Android Recyclerview,我正在为用户编写一个简单的搜索程序,但我的应用程序没有显示查询结果,在我单击搜索后,有40%的时间会崩溃。这是我的密码。如有任何建议,将不胜感激 我的活动: import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.

我正在为用户编写一个简单的搜索程序,但我的应用程序没有显示查询结果,在我单击搜索后,有40%的时间会崩溃。这是我的密码。如有任何建议,将不胜感激

我的活动:

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.MyApp.Objects.ParticipantsObject;
import com.MyApp.R;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;



public class ParticipantsActivity extends AppCompatActivity {

    private EditText mSearchField;
    private ImageButton mSearchBtn;
    private RecyclerView mResultList;
    private DatabaseReference mUserDatabase;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_neighbors);

        mUserDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child("Participants");
        mSearchField = (EditText) findViewById(R.id.search_field);
        mSearchBtn = (ImageButton) findViewById(R.id.search_btn);
        mResultList = (RecyclerView) findViewById(R.id.result_list);
        mResultList.setHasFixedSize(true);
        mResultList.setLayoutManager(new LinearLayoutManager(this));

        mSearchBtn.setOnClickListener(view -> {

            String searchText = mSearchField.getText().toString();
            firebaseUserSearch(searchText);

        });

    }

    private void firebaseUserSearch(String searchText) {
        Toast.makeText(ParticipantsActivity.this, "Started Search", Toast.LENGTH_LONG).show();
        Query firebaseSearchQuery = mUserDatabase.orderByChild("name").startAt(searchText);


        FirebaseRecyclerOptions<ParticipantsObject> firebaseRecyclerOptions = new FirebaseRecyclerOptions.Builder<ParticipantsObject>()
                .setQuery(firebaseSearchQuery, ParticipantsObject.class)
                .build();

        class UserHolder extends RecyclerView.ViewHolder {
            private TextView imageThumbTextView, nameTextView     
            UserHolder(View itemView) {
                super(itemView);
                imageThumbTextView = itemView.findViewById(R.id.profile_image);
                nameTextView = itemView.findViewById(R.id.name_text);
            }


            void setUsers(ParticipantsObject participantsObject) {
                String imageThumb = driverObject.getThumb_image();
                imageThumbTextView.setText(imageThumb);
                String name = participantsObject.getName();
                nameTextView.setText(name);
            }
        }

        FirebaseRecyclerAdapter<ParticipantsObject, UserHolder> firebaseRecyclerAdapter;

        firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<ParticipantsObject, UserHolder>(firebaseRecyclerOptions) {
            @Override
            protected void onBindViewHolder(@NonNull UserHolder userHolder, int position, @NonNull ParticipantsObject participantsObject) {
                userHolder.setUsers(participantsObject);
            }

            @Override
            public UserHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_layout, parent, false);

                return new UserHolder(view);
            }
        };
        mResultList.setAdapter(firebaseRecyclerAdapter);
        firebaseRecyclerAdapter.startListening();

    }


}
import androidx.annotation.NonNull;
导入androidx.appcompat.app.appcompat活动;
导入androidx.recyclerview.widget.LinearLayoutManager;
导入androidx.recyclerview.widget.recyclerview;
导入android.os.Bundle;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.EditText;
导入android.widget.ImageButton;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.MyApp.Objects.ParticipantsObject;
导入com.MyApp.R;
导入com.firebase.ui.database.FirebaseRecyclerAdapter;
导入com.firebase.ui.database.FirebaseRecyclerOptions;
导入com.google.firebase.database.DatabaseReference;
导入com.google.firebase.database.FirebaseDatabase;
导入com.google.firebase.database.Query;
公共课堂参与者活动扩展了AppCompatActivity{
私有编辑文本字段;
专用图像按钮mSearchBtn;
私人回收站查看mResultList;
私人数据库参考博物馆数据库;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u邻居);
mUserDatabase=FirebaseDatabase.getInstance().getReference().child(“用户”).child(“参与者”);
mSearchField=(EditText)findViewById(R.id.search_字段);
mSearchBtn=(ImageButton)findViewById(R.id.search\u btn);
mResultList=(RecyclerView)findViewById(R.id.result\u list);
mResultList.setHasFixedSize(true);
mResultList.setLayoutManager(新的LinearLayoutManager(this));
mSearchBtn.setOnClickListener(视图->{
String searchText=mSearchField.getText().toString();
firebaseUserSearch(searchText);
});
}
私有void firebaseUserSearch(字符串搜索文本){
Toast.makeText(ParticipantsActivity.this,“开始搜索”,Toast.LENGTH_LONG.show();
Query firebasearchquery=mUserDatabase.orderByChild(“名称”).startAt(searchText);
FirebaseRecyclerOptions FirebaseRecyclerOptions=新建FirebaseRecyclerOptions.Builder()
.setQuery(firebaseSearchQuery,ParticipantsObject.class)
.build();
类UserHolder扩展了RecyclerView.ViewHolder{
私有文本视图imageThumbTextView,nameTextView
用户持有者(查看项目视图){
超级(项目视图);
imageThumbTextView=itemView.findViewById(R.id.profile\u图像);
nameTextView=itemView.findviewbyd(R.id.name\u text);
}
void setUsers(ParticipantsObject ParticipantsObject){
字符串imageThumb=driverObject.getThumb_image();
imageThumbTextView.setText(imageThumb);
字符串名称=participantsObject.getName();
nameTextView.setText(名称);
}
}
FirebaseRecyclerAdapter FirebaseRecyclerAdapter;
firebaseRecyclerAdapter=新的firebaseRecyclerAdapter(firebaseRecyclerOptions){
@凌驾
受保护的无效onBindViewHolder(@NonNull UserHolder UserHolder,int position,@NonNull ParticipantsObject ParticipantsObject){
userHolder.setUsers(participantsObject);
}
@凌驾
public UserHolder onCreateViewHolder(视图组父级,int-viewType){
View=LayoutFlater.from(parent.getContext()).flate(R.layout.list\u布局,parent,false);
返回新的用户持有者(视图);
}
};
mResultList.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.startListening();
}
}
My activity_particients.xml:

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        tools:context="com.MyApp.ParticipantsActivity">


        <TextView
            android:id="@+id/heading_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="30dp"
            android:text="Firebase Search"
            android:textColor="#555555"
            android:textSize="24sp" />

        <EditText
            android:id="@+id/search_field"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/heading_label"
            android:layout_below="@+id/heading_label"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:layout_toStartOf="@+id/search_btn"
            android:background="@drawable/search_layout"
            android:ems="10"
            android:hint="Search here"
            android:inputType="textPersonName"
            android:paddingBottom="10dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:paddingTop="10dp"
            android:textColor="#999999"
            android:textSize="16sp" />

        <ImageButton
            android:id="@+id/search_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/search_field"
            android:layout_alignParentEnd="true"
            android:layout_alignTop="@+id/search_field"
            android:layout_marginRight="30dp"
            android:background="@android:color/background_light"
            app:srcCompat="@mipmap/search_button" />


    <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/result_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/search_field"
            android:layout_marginTop="50dp">
    </androidx.recyclerview.widget.RecyclerView>

    </RelativeLayout>

我的列表布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/profile_image"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="20dp"
        app:srcCompat="@mipmap/ic_default_user" />

    <TextView
        android:id="@+id/name_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_marginStart="14dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="50dp"

        android:layout_marginEnd="213dp"
        android:layout_marginRight="20dp"
        android:layout_toEndOf="@+id/profile_image"
        android:text="Username"
        android:textColor="#555555"
        android:textSize="16sp" />

</RelativeLayout>

有人知道为什么不显示结果吗? 我的相关Firebase DB基本路径如下所示: 用户->参与者->用户ID->名称、图像等


Logcat目前没有给我太多信息。

请发布数据库结构,而不是解释您的数据库结构。如果应用程序崩溃,则会出现堆栈跟踪。请在logcat上查找,并将其添加到您的问题中。请同时回复@AlexMa@AlexMa今天它并没有崩溃,但它说的是“E/RecyclerView:没有连接适配器;跳过布局。”没有显示任何数据。我找到了三个这样的修复方法,但是它们与布局管理器(已经设置)和适配器设置(我想我已经设置了)有关。有什么想法吗?