Невозможно преобразовать объект типа java.lang.String в тип sort.media.sound.audio.workshoplecture2.Contacts Это ошибка, которую я получаю.
import com.squareup.picasso.Picasso;
import de.hdodenhof.circleimageview.CircleImageView;
public class FindFriendActivity extends AppCompatActivity {
private Toolbar mToolBar;
private RecyclerView FindFriendsRecylerList;
private DatabaseReference UsersRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_friend);
UsersRef= FirebaseDatabase.getInstance().getReference().child("Users");
FindFriendsRecylerList=(RecyclerView) findViewById(R.id.find_friends_recycler_lists);
FindFriendsRecylerList.setLayoutManager(new LinearLayoutManager(this));
mToolBar=(Toolbar) findViewById(R.id.find_friends_toolbar);
setSupportActionBar(mToolBar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle("Find Friends");
}
@Override
public void onStart()
{
super.onStart();
FirebaseRecyclerOptions<Contacts> options=new FirebaseRecyclerOptions.Builder<Contacts>
().setQuery(UsersRef,Contacts.class).build();
FirebaseRecyclerAdapter<Contacts,FindFriendsViewHolder> adapter=new FirebaseRecyclerAdapter<Contacts, FindFriendsViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull FindFriendsViewHolder holder, int position, @NonNull Contacts model) {
model=new Contacts();
holder.userName.setText(model.getName());
holder.userStatus.setText(model.getStatus());
Picasso.get().load(model.getImage()).into(holder.profileImage);
}
@NonNull
@Override
public FindFriendsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view= LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.users_display_layout,viewGroup,false);
FindFriendsViewHolder findFriendsViewHolder=new FindFriendsViewHolder(view);
return findFriendsViewHolder;
}
};
FindFriendsRecylerList.setAdapter(adapter);
adapter.startListening();
}
public static class FindFriendsViewHolder extends RecyclerView.ViewHolder
{
TextView userName,userStatus;
CircleImageView profileImage;
public FindFriendsViewHolder(@NonNull View itemView) {
super(itemView);
userName=itemView.findViewById(R.id.users_profile_name);
userStatus=itemView.findViewById(R.id.users_status);
profileImage=itemView.findViewById(R.id.users_profile_image);
}
}
}
My Contacts Class
package sort.media.sound.audio.workshoplecture2;
public class Contacts {
String name;
String image;
String status;
public Contacts()
{
}
public Contacts(String name, String image, String status) {
this.name = name;
this.image = image;
this.status = status;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}