gpt4 book ai didi

java - com.google.firebase.database.DatabaseException : Found two getters or fields with conflicting case sensitivity for property: user_name

转载 作者:行者123 更新时间:2023-11-30 00:25:24 27 4
gpt4 key购买 nike

此代码在从 Firebase 数据库中提取数据时出错
在行中

UsersForChat usersForChat = dataSnapshot.getValue(UsersForChat.class); com.google.firebase.database.DatabaseException:发现两个 getter 或属性的大小写敏感度冲突的字段:user_name

public class Users_Display_For_Chat_Activity extends AppCompatActivity {

FirebaseAuth firebaseAuth;

FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;

ArrayList<UsersForChat> users = new ArrayList<UsersForChat>();

RecyclerView recyclerView;
UsersDispalyActivtyRecyclerViewAdapter rvadapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat_);

firebaseAuth = FirebaseAuth.getInstance();

firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference();

rvadapter = new UsersDispalyActivtyRecyclerViewAdapter(this,users);



recyclerView = (RecyclerView) findViewById(R.id.rv_UsersForChat);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(rvadapter);

retrivedata();
}

public void retrivedata()
{
databaseReference.child("Users").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
UsersForChat usersForChat = dataSnapshot.getValue(UsersForChat.class);
users.add(usersForChat);
}

@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {

}

@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {

}

@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}
}

这是 Pojo 类 UsersForChat

public class UsersForChat {

String User_Name,User_PhoneNo,User_Profile_Pic_Url;

public UsersForChat()
{

}

public UsersForChat(String User_Name, String User_PhoneNo, String User_Profile_Pic_Url) {
this.User_Name = User_Name;
this.User_PhoneNo = User_PhoneNo;
this.User_Profile_Pic_Url = User_Profile_Pic_Url;
}

public String getUser_Name() {
return User_Name;
}

public String getUser_PhoneNo() {
return User_PhoneNo;
}

public String getUser_Profile_Pic_Url() {
return User_Profile_Pic_Url;
}

public void setUser_Name(String user_Name) {
User_Name = user_Name;
}

public void setUser_PhoneNo(String user_PhoneNo) {
User_PhoneNo = user_PhoneNo;
}

public void setUser_Profile_Pic_Url(String user_Profile_Pic_Url) {
User_Profile_Pic_Url = user_Profile_Pic_Url;
}
}

最佳答案

如果您处于项目的开始阶段并且可以进行数据库更改,我建议您根据Java Naming Convention 将所有字段名称、setter 和getter 更改为小写。 .

此外,您需要将所有字段的可见性从默认访问权限更改为私有(private)访问权限,如下所示:

private String userName, userPhoneNo, userProfilePicUrl;

像这样的 setter 和 getter:

public void setUserEmail(String userEmail) {this.userEmail = userEmail;}    
public String getUserEmail() {return userEmail;}

public String getUserPhoneNo() {return userPhoneNo;}
public void setUserPhoneNo(String userPhoneNo) {this.userPhoneNo = userPhoneNo;}

public String getUserProfilePicUrl() {return userProfilePicUrl;}
public void setUserProfilePicUrl(String userProfilePicUrl) {this.userProfilePicUrl = userProfilePicUrl;}

正如您可能看到的,只有 setter 和 getter 具有公共(public)访问权限

如果您无法更改数据库中字段的名称,那么您只需更改字段的可见性即可。

关于java - com.google.firebase.database.DatabaseException : Found two getters or fields with conflicting case sensitivity for property: user_name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45468264/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com