android - 试图检索用户数据
问题描述
我正在尝试检索用户保存的其他数据,例如他们的帖子、他们上传的图像、描述和帖子的名称,并将其显示在回收站视图中。所有这些信息都保存在一个随机密钥的文件夹中。当我试图检索所有内容时,除了一个空的卡片视图外,什么都没有显示,而且我注意到我收到了这三个警告消息2020-05-06 11:19:50.473 11745-11745/com.myapp.jappy W/ClassMapper: No setter/field for firstname found on class com.myapp.jappy.UserInformation
2020-05-06 11:19:50.474 11745-11745/com.myapp.jappy W/ClassMapper: No setter/field for email found on class com.myapp.jappy.UserInformation
2020-05-06 11:19:50.474 11745-11745/com.myapp.jappy W/ClassMapper: No setter/field for lastname found on class com.myapp.jappy.UserInformation
,但我并没有尝试获取用户的电子邮件、名字和姓氏。他们的东西与保存一切的方式有关吗?有人可以帮我解决这个问题。提前致谢。
//Model
public class Upload {
private String ImageUrl;
private String post;
private String post_name;
private String description;
public Upload(String imageUrl, String postname, String postt, String descrip) {
ImageUrl = imageUrl;
post = postt;
post_name = postname;
description = descrip;
}
//Empty constructor needed
public Upload() {
}
public String getImageUrl() {
return ImageUrl;
}
public void setImageUrl(String imageUrl) {
ImageUrl = imageUrl;
}
public String getPost() {
return post;
}
public void setPost(String post) {
this.post = post;
}
public String getPost_name() {
return post_name;
}
public void setPost_name(String post_name) {
this.post_name = post_name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
//Adapter class
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder>{
private Context mContext;
private ArrayList<Upload> users;
public ImageAdapter(Context context, ArrayList<Upload> uploads){
is 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).getDescription());
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);
}
}
}
//Profile page
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();
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);
//getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,firstFragment);
databaseReference.child(uid).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
UserInformation upload = dataSnapshot.getValue(UserInformation.class);
myUploads.add(upload);
aAdapter = new ImageAdapter(ProfileActivity.this, myUploads);
recyclerView.setAdapter(aAdapter);
aAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(ProfileActivity.this, databaseError.getMessage(), Toast.LENGTH_LONG).show();
}
});
解决方案
你Users Node
必须看起来像这样:
Users
|
|------UID
|
_____email
_____firstname
_____lastname
|------UID2
..........
..........
..........
您现在必须添加一个新节点posts
:
Upload
|
|------randomID
|_____ImageUrl
_____description
_____post
_____post_name
|------randomID2
..........
..........
..........
上课Users
:
public class Users {
//add these
private String email;
private String firstname;
private String lastname;
//constrcutor becomes
public Upload(String email, String firstname, String lastname) {
this.email = email;
this.firstname = firstname;
this.lastname = lastname;
}
//also create getters and setters for email , firstname , lastname..........
您的Upload
课程将如下所示:
public class Upload {
private String ImageUrl;
private String post;
private String post_name;
private String description;
//constrcutor
public Upload(String imageUrl, String postname, String postt, String descrip) {
ImageUrl = imageUrl;
post = postt;
post_name = postname;
description = descrip;
}
//also create getters and setters for all the fields
推荐阅读
- javascript - JavaScript - 与 parentNode.replaceChild 结合使用时,我无法让 appendChild 操作工作
- javascript - 如何限制每行 textarea 的字节数?
- java - 当我点击金额时,我想在图片下方,金额将自动出现在我的编辑文本中,金额是文本视图
- c - 如何声明加载动态库后可见的外部变量?
- c# - MainWindow 的 Frame.Content 在作为引用参数传递给另一个窗口时消失
- c# - Update From Bootstrap 3.7 to 5.0.2 in .net mvc producing Error- System.NullReferenceException
- spring - 如何将用户名发送到另一个页面 Spring Boot
- gitlab-ci - 如何从多个作业中引用变量?
- ios - xcode 12.5.1 在归档过程完成之前崩溃
- python-3.9 - 遍历父文件夹中的每个子文件夹,并删除每个子文件夹中修改日期大于 x 天的所有文件和文件夹