Process: mishelb.app.globe_all, PID: 11971
com.google.firebase.database.DatabaseException: Found conflicting getters for name: isChangingConfigurations
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.<init>(CustomClassMapper.java:478)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.loadOrCreateBeanMapperForClass(CustomClassMapper.java:330)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(CustomClassMapper.java:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToPlainJavaTypes(CustomClassMapper.java:61)
at com.google.firebase.database.DatabaseReference.setValueInternal(DatabaseReference.java:282)
at com.google.firebase.database.DatabaseReference.setValue(DatabaseReference.java:159)
at com.example.globe_all.SignupScreen.updateUI(SignupScreen.java:92)
at com.example.globe_all.SignupScreen$2.onComplete(SignupScreen.java:77)
at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks@@18.0.1:1)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
So I have this in my log. I am using android studio and Firebase, and after trying to
mDataBase.child(keyID).setValue(u);
I get this error code.
Here is the entirety of the code:
package com.example.globe_all;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class SignupScreen extends AppCompatActivity {
private DatabaseReference mDataBase;
private FirebaseDatabase database;
private FirebaseAuth mAuth;
private static final String USER = "user";
private EditText user, email, pass, passRep;
private Button signup;
private User u;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup_screen);
user = findViewById(R.id.user);
email = findViewById(R.id.email);
pass = findViewById(R.id.password);
passRep = findViewById(R.id.pass_repeat);
signup = findViewById(R.id.signu);
database = FirebaseDatabase.getInstance();
mDataBase = database.getReference();
mAuth = FirebaseAuth.getInstance();
signup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!(TextUtils.isEmpty(email.getText().toString()) && TextUtils.isEmpty(user.getText().toString()) &&
TextUtils.isEmpty(pass.getText().toString()) && TextUtils.isEmpty(passRep.getText().toString())) &&
pass.getText().toString().equals(passRep.getText().toString())) {
u = new User(user.getText().toString(), email.getText().toString(),
pass.getText().toString());
registerUser(email.getText().toString(), pass.getText().toString());
}
}
});
}
public void registerUser(String email, String password) {
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
Log.d("FAIL", "process failed");
}
}
});
}
public void updateUI (FirebaseUser currentU) {
String keyID = mDataBase.push().getKey();
u.setId(keyID);
assert keyID != null;
mDataBase.child(keyID).setValue(u);
Intent login = new Intent(this, LoginScreen.class);
}
}
After attempting the solution provided by Ticherhaz, still get the error:
Process: mishelb.app.globe_all, PID: 8895
com.google.firebase.database.DatabaseException: Found conflicting getters for name: isChangingConfigurations
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.<init>(CustomClassMapper.java:478)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.loadOrCreateBeanMapperForClass(CustomClassMapper.java:330)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(CustomClassMapper.java:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToPlainJavaTypes(CustomClassMapper.java:61)
at com.google.firebase.database.DatabaseReference.setValueInternal(DatabaseReference.java:282)
at com.google.firebase.database.DatabaseReference.setValue(DatabaseReference.java:159)
at com.example.globe_all.SignupScreen.updateUI(SignupScreen.java:89)
at com.example.globe_all.SignupScreen$2.onComplete(SignupScreen.java:75)
at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks@@18.0.1:1)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
CodePudding user response:
You re-set back the setId
. You are suppose to use the param
itself.
At the onClick
you comment this line object
. So it will become like this.
if (!(TextUtils.isEmpty(email.getText().toString()) && TextUtils.isEmpty(user.getText().toString()) &&
TextUtils.isEmpty(pass.getText().toString()) && TextUtils.isEmpty(passRep.getText().toString())) && pass.getText().toString().equals(passRep.getText().toString())) {
//Comment this line
//u = new User(user.getText().toString(), email.getText().toString(), pass.getText().toString());
registerUser(email.getText().toString(), pass.getText().toString());
}
And then at the updateUi
method, you create the User
object.
public void updateUI (FirebaseUser currentU) {
final String keyID = mDataBase.push().getKey();
final User userToDB = new User(keyID, user.getText().toString(), email.getText().toString(), pass.getText().toString());
mDataBase.child(keyID).setValue(userToDB);
Intent login = new Intent(this, LoginScreen.class);
}
UPDATE
Since the error regarding your User
class, related with isChangingConfigurations
. You need to rename the variable
since this is reserve to the Firebase
Change
isChangingConfigurations
to
isChangingConfigures
CodePudding user response:
Thanks everyone for the answers, I finally figured it out.
In turns out the database requires my User class to have get() and set()
methods for each of the class' properties.
After setting these up, and inserting my realtime-database URL in:
database = FirebaseDatabase.getInstance(URL);
It finally worked!