我收到此警告,然后是后续的NullpointerException。
在仔细阅读文章之后,我尝试确保我的Java类名称与我的Firebase数据库中的名称相匹配,但我仍然收到错误。
警告/错误:
01-03 13:03:01.963 23252-23252/? I/FirebaseMethods: checkIfUsernameExists: checking if imail@address.com already exists.
01-03 13:03:01.965 23252-23252/? I/FirebaseMethods: checkIfUsernameExists: datasnapshot: DataSnapshot { key = RC9zIioE6vc5vlhrIethmbqyFDS2, value = {Social_Security_Number=5555, Email_Address=imail@address.com} }
01-03 13:03:01.981 23252-23252/? W/ClassMapper: No setter/field for Social_Security_Number found on class com.netgalaxystudios.timeclock.Models.EmployeeUser
01-03 13:03:01.981 23252-23252/? W/ClassMapper: No setter/field for Email_Address found on class com.netgalaxystudios.timeclock.Models.EmployeeUser
01-03 13:03:01.981 23252-23252/? I/FirebaseMethods: checkIfUsernameExists: email: null
01-03 13:03:01.987 23252-23252/? E/UncaughtException: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at com.netgalaxystudios.timeclock.Adapters.FirebaseMethods.checkIfUsernameExists(FirebaseMethods.java:46)
at com.netgalaxystudios.timeclock.Activities.RegisterEmployeeActivity$1$1.onDataChange(RegisterEmployeeActivity.java:122)
FirebaseMethods.java:
public boolean checkIfUsernameExists(String emailAddress, DataSnapshot datasnapshot){
Log.i(TAG, "checkIfUsernameExists: checking if " + emailAddress + " already exists.");
EmployeeUser user = new EmployeeUser();
for (DataSnapshot ds: datasnapshot.getChildren()){
Log.i(TAG, "checkIfUsernameExists: datasnapshot: " + ds);
user.setEmailAddress(ds.getValue(EmployeeUser.class).getEmailAddress());
Log.i(TAG, "checkIfUsernameExists: email: " + user.getEmailAddress());
if(user.getEmailAddress().equals(emailAddress)){
Log.i(TAG, "checkIfUsernameExists: FOUND A MATCH: " + user.getEmailAddress());
return true;
}
EmployeeUser.java:
public class EmployeeUser {
private String user_id;
private String Email_Address;
private String Social_Security_Number;
public EmployeeUser(String user_id, String Email_Address, String Social_Security_Number) {
this.user_id = user_id;
this.Email_Address = Email_Address;
this.Social_Security_Number = Social_Security_Number;
}
public EmployeeUser(String Email_Address) {
this.Email_Address = Email_Address;
}
public EmployeeUser() {}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getEmailAddress() {
return Email_Address;
}
public void setEmailAddress(String emailAddress) {
this.Email_Address = emailAddress;
}
public String getSocialSecurityNumber() {
return Social_Security_Number;
}
public void setSocialSecurityNumber(String socialSecurityNumber) {
this.Social_Security_Number = socialSecurityNumber;
}
}
RegisterEmployeeActivity.java:
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//1st check: Make sure the username is not already in use
Log.i("DATA VALUE", dataSnapshot.child("RC9zIioE6vc5vlhrIethmbqyFDS2").getValue().toString());
if (firebaseMethods.checkIfUsernameExists(email, dataSnapshot)) {
auth.createUserWithEmailAndPassword(emailET.getText().toString(), passwordET.getText().toString())
.addOnCompleteListener(RegisterEmployeeActivity.this, new OnCompleteListener() {
答案 0 :(得分:1)
根据 Java Naming conventions ,您的模型类应如下所示:
Mailto: sampleemailadress@email.com (from a specific cell value in excel "=Sheet1!A1")
CC:( from a specific cell value in excel "=Sheet1!A2" )
Body: ( from a specific Range in excel "=Sheet2!A1:B24" )
Attachment : (from a specific cell value in excel "=Sheet1!A1") ....Value in Cell - " C:\Users\User1\Downloads\sampleexcelsheet.xlsm "
您收到public class EmployeeUser {
private String userId;
private String emailAddress;
private String socialSecurityNumber;
public EmployeeUser(String userId, String emailAddress, String socialSecurityNumber) {
this.userId = userId;
this.emailAddress = emailAddress;
this.socialSecurityNumber = socialSecurityNumber;
}
public EmployeeUser(String emailAddress) {
this.emailAddress = emailAddress;
}
public EmployeeUser() {}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getSocialSecurityNumber() {
return socialSecurityNumber;
}
public void setSocialSecurityNumber(String socialSecurityNumber) {
this.socialSecurityNumber = socialSecurityNumber;
}
}
错误,因为Firebase正在根据您的No setter/field for Social_Security_Number found on class
getter方法查找名为socialSecurityNumber
的字段。您的字段为getSocialSecurityNumber()
而不是Social_Security_Number
,因此该错误。