Я пытаюсь получить сохраненные данные пользователей и отобразить их на странице своего профиля, используя представление переработчика. Когда я запускаю свое приложение, чтобы увидеть, все ли работает нормально, но мое приложение продолжает падать и перестает работать. Я получил ошибку com.google.firebase.database.DatabaseException: Failed to convert value of type java.util.HashMap to String
. У меня была эта работа раньше, но я не уверен, в чем проблема сейчас. Может ли кто-нибудь помочь мне решить эту проблему. Заранее спасибо. Обновлена база данных
Адаптер изображения
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder>{
private Context mContext;
private ArrayList<UserInformation> users;
public ImageAdapter(Context context, ArrayList<UserInformation> uploads){
mContext = context;
users = uploads;
}
@NonNull
@Override
public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View V = LayoutInflater.from(mContext).inflate(R.layout.cardview, parent, false);
return new ImageViewHolder(V);
}
@Override
public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
//String uploadCurrent=users.get(position).getmImageUrl();
holder.txt1.setText(users.get(position).getAction());
Picasso.get().load(users.get(position).getmImageUrl()).fit().centerCrop().into(holder.imageView);
}
@Override
public int getItemCount() {
return users.size();
}
public class ImageViewHolder extends RecyclerView.ViewHolder{
public ImageView imageView;
public TextView txt1;
public ImageViewHolder(@NonNull View itemView) {
super(itemView);
imageView=itemView.findViewById(R.id.imageview);
//txt1=itemView.findViewById(R.id.action);
}
}
}
Класс модели
public UserInformation(String mImageUrl, String cate, String action, String headline, String websiteurl) {
this.mImageUrl = mImageUrl;
this.cate = cate;
this.action = action;
this.headline = headline;
this.websiteurl = websiteurl;
}
public UserInformation() {
}
public String getmImageUrl() {
return mImageUrl;
}
public void setmImageUrl(String mImageUrl) {
this.mImageUrl = mImageUrl;
}
public String getCategory() {
return cate;
}
public void setCategory(String category) {
this.cate = cate;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getHeadline() {
return headline;
}
public void setHeadline(String header) {
this.headline = headline;
}
public String getWebsiteurl() {
return websiteurl;
}
public void setWebsiteurl(String websiteurl) {
this.websiteurl = websiteurl;
}
}
Основной класс
recyclerView = findViewById(R.id.recyclerView);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(),3);
recyclerView.setLayoutManager(layoutManager);
myUploads = new ArrayList<UserInformation>();
aAdapter = new ImageAdapter(ProfileActivity.this, myUploads);
recyclerView.setAdapter(aAdapter);
aAdapter.notifyDataSetChanged();
h=new Handler();
databaseReference = FirebaseDatabase.getInstance().getReference("Users");
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
firebaseStorage = FirebaseStorage.getInstance();
storageReference = firebaseStorage.getReference();
firebaseUser = firebaseAuth.getInstance().getCurrentUser();
t=findViewById(R.id.none);
databaseReference.child(uid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot postsnapshot : dataSnapshot.getChildren()) {
UserInformation upload=postsnapshot.getValue(UserInformation.class);
myUploads.add(upload);
aAdapter = new ImageAdapter(ProfileActivity.this, myUploads);
recyclerView.setAdapter(aAdapter);
}