com.google.firebase.database.DatabaseException:无法将类型java.util.ArrayList的值转换为String

时间:2019-04-08 05:33:23

标签: android firebase search firebase-realtime-database

我正在Firebase数据库(实时数据库)中进行搜索,但是作为回报,我遇到了这些错误,有人可以帮我解决这个问题吗? 该搜索是通过应用程序完成的,我遇到以下错误

  

PID:15597       com.google.firebase.database.DatabaseException:无法将类型java.util.ArrayList的值转换为String

维护性

public class SalasActivity 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_salas);

    mUserDatabase = FirebaseDatabase.getInstance().getReference("grupos");


    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(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

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

            firebaseUserSearch(searchText);

        }
    });

}

private void firebaseUserSearch(String searchText) {

    Toast.makeText(SalasActivity.this, "Started Search", Toast.LENGTH_LONG).show();

    Query firebaseSearchQuery = mUserDatabase.orderByChild("nome").startAt(searchText).endAt(searchText + "\uf8ff");

    FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(

            Users.class,
            R.layout.list_layout,
            UsersViewHolder.class,
            firebaseSearchQuery

    ) {
        @Override
        protected void populateViewHolder(UsersViewHolder viewHolder, Users model, int position) {


            viewHolder.setDetails(getApplicationContext(), model.getName(), model.getStatus(), model.getImage());

        }
    };

    mResultList.setAdapter(firebaseRecyclerAdapter);

}


// View Holder Class

public static class UsersViewHolder extends RecyclerView.ViewHolder {

    View mView;

    public UsersViewHolder(View itemView) {
        super(itemView);

        mView = itemView;

    }

    public void setDetails(Context ctx, String userName, String userStatus, String userImage){

        TextView user_name = (TextView) mView.findViewById(R.id.name_text);
        TextView user_status = (TextView) mView.findViewById(R.id.status_text);
        ImageView user_image = (ImageView) mView.findViewById(R.id.profile_image);


        user_name.setText(userName);
        user_status.setText(userStatus);

        Glide.with(ctx).load(userImage).into(user_image);

USERS.JAVA

public class Users {

public String nome, membros, id;

public Users(){

}

public String getName() {
    return nome;
}

public void setName(String name) {
    this.nome = name;
}

public String getImage() {
    return membros;
}

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

public String getStatus() {
    return id;
}

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

public Users(String name, String image, String status) {
    this.nome = name;
    this.membros = image;
    this.id = status;
    }
}

数据库 DATABASE IMAGE

0 个答案:

没有答案