英文:
Found two getters or fields with conflicting case sensitivity for property: status
问题
当我运行我的应用程序时,它崩溃并显示它得到了两个status的getter。但是在我的代码中,我写的是Status而不是status。我不知道哪里出了问题,请帮助我!以下是 Contacts.java
的代码部分:
public class Contacts
{
public String name, Status, image;
public Contacts()
{
}
public Contacts(String name, String Status, String image)
{
this.name = name;
this.Status = Status;
this.image = image;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return Status;
}
public void setStatus(String status) {
this. Status = status;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}
以下是 FindFreindsActivity.java
的代码部分:
public class FindFreindsActivity extends AppCompatActivity {
private Toolbar mToolbar;
private RecyclerView FindfreindsRecyclerList;
private DatabaseReference UsersRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_freinds);
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
FindfreindsRecyclerList = (RecyclerView) findViewById(R.id.find_freinds_recycler_list);
FindfreindsRecyclerList.setLayoutManager(new LinearLayoutManager(this));
mToolbar = (Toolbar) findViewById(R.id.find_freinds_toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Find Friends");
}
@Override
protected void onStart()
{
FirebaseRecyclerOptions<Contacts> options =
new FirebaseRecyclerOptions.Builder<Contacts>()
.setQuery(UsersRef, Contacts.class)
.build();
super.onStart();
FirebaseRecyclerAdapter<Contacts,FindFreindsViewHolder >adapter =
new FirebaseRecyclerAdapter<Contacts, FindFreindsViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull FindFreindsViewHolder holder, final int position, @NonNull Contacts model) {
holder.userName.setText(model.getName());
holder.userStatus.setText(model.getStatus());
Picasso.get().load(model.getImage()).placeholder(R.drawable.profile_image).into(holder.profileImage);
}
@NonNull
@Override
public FindFreindsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i)
{
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.users_display_layout, viewGroup, false);
FindFreindsViewHolder viewHolder = new FindFreindsViewHolder(view);
return viewHolder;
}
};
FindfreindsRecyclerList.setAdapter(adapter);
adapter.startListening();
}
public static class FindFreindsViewHolder extends RecyclerView.ViewHolder
{
TextView userName, userStatus;
CircleImageView profileImage;
public FindFreindsViewHolder(@NonNull View itemView) {
super(itemView);
userName = itemView.findViewById(R.id.user_profile_name);
userStatus = itemView.findViewById(R.id.user_status);
profileImage = itemView.findViewById(R.id.users_profile_image);
}
}
}
在我的Firebase数据库中,状态被写成了Status,这个活动应该显示使用这个应用程序的所有人,包括他们的个人资料图片、用户名和状态。
英文:
When i run my app it crashes and says it gets two getters of status. But in my code i have written Status not status. I don't know what is wrong please help me!
This is Contacts.java
public class Contacts
{
public String name, Status, image;
public Contacts()
{
}
public Contacts(String name, String Status, String image)
{
this.name = name;
this.Status = Status;
this.image = image;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return Status;
}
public void setStatus(String status) {
this. Status = status;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}
Here is FindFreindsActivity.java
public class FindFreindsActivity extends AppCompatActivity {
private Toolbar mToolbar;
private RecyclerView FindfreindsRecyclerList;
private DatabaseReference UsersRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_freinds);
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
FindfreindsRecyclerList = (RecyclerView) findViewById(R.id.find_freinds_recycler_list);
FindfreindsRecyclerList.setLayoutManager(new LinearLayoutManager(this));
mToolbar = (Toolbar) findViewById(R.id.find_freinds_toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Find Freinds");
}
@Override
protected void onStart()
{
FirebaseRecyclerOptions<Contacts> options =
new FirebaseRecyclerOptions.Builder<Contacts>()
.setQuery(UsersRef, Contacts.class)
.build();
super.onStart();
FirebaseRecyclerAdapter<Contacts,FindFreindsViewHolder >adapter =
new FirebaseRecyclerAdapter<Contacts, FindFreindsViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull FindFreindsViewHolder holder, final int position, @NonNull Contacts model) {
holder.userName.setText(model.getName());
holder.userStatus.setText(model.getStatus());
Picasso.get().load(model.getImage()).placeholder(R.drawable.profile_image).into(holder.profileImage);
}
@NonNull
@Override
public FindFreindsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i)
{
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.users_display_layout, viewGroup, false);
FindFreindsViewHolder viewHolder = new FindFreindsViewHolder(view);
return viewHolder;
}
};
FindfreindsRecyclerList.setAdapter(adapter);
adapter.startListening();
}
public static class FindFreindsViewHolder extends RecyclerView.ViewHolder
{
TextView userName, userStatus;
CircleImageView profileImage;
public FindFreindsViewHolder(@NonNull View itemView) {
super(itemView);
userName = itemView.findViewById(R.id.user_profile_name);
userStatus = itemView.findViewById(R.id.user_status);
profileImage = itemView.findViewById(R.id.users_profile_image);
}
}
}
In my firebase database status is written as Status and this activity is supposed to show all the people using this app, with their profile pic , username and their status.
答案1
得分: 1
你的Contacts对象提供了两种获取名为“status”的属性的方法。
第一种是将Status
声明为public成员:
public String name, Status, image;
第二种是使用访问器方法:
public String getStatus() {
return Status;
}
编写POJO对象的标准方式是将字段设为private,并仅提供公共访问器方法。
请改为如下方式:
private String name, status, image;
还考虑将status
改为小写,这是Java对象字段的标准写法。
英文:
Your Contacts object provides two ways to get a property called "status".
The first one is the fact that you've made Status
a public member:
public String name, Status, image;
The second is your accessor method:
public String getStatus() {
return Status;
}
The standard way to write POJO objects is to make your fields private and provide only public accessor methods.
Do this instead:
private String name, Status, image;
Also consider making status
lowercase, as is the standard for Java object fields.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论