I'm making a project using Firebase Auth and Realtime Database and I recieved the error
com.google.android.apps.gsa.shared.exception.GsaIOException: Error code: 393238 | Buffer overflow, no available space.
when trying to create a new account and fetch the user's data (I want to send that to another activity through an intent). I believe this error was solved by uninstalling the app and running again.
EDITED: I ran again and now the error is a Null Pointer Exception on the User created. Here's the new error as it appears in the Logcat:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.stud.scriptreality.classes.User.getEmail()' on a null object reference
at com.stud.scriptreality.Register$1$1.onDataChange(Register.java:82)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.2.1:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.2.1:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.2.1:55)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
The thing is when checking the list of users in Firebase Auth, the user appears to be created, but my Android app crashes.
I set the database refference like this:
firebaseUser = auth.getCurrentUser();
myRef = database.getReference("users").child(firebaseUser.getUid());
In the code below I have the listener for fetching the data from Realtime Database and myRef is the refference to the database. I believe the problem is here somewhere, since the registration of the Firebase User is working.
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String useremail = dataSnapshot.child("users").getValue(User.class).getEmail(); //this is line 82
String userpassword = dataSnapshot.child("users").getValue(User.class).getPassword();
String userjob = dataSnapshot.child("users").getValue(User.class).getJob();
user = new User(useremail,userpassword,userjob);
if(user!=null){
switch (userjob){
case "Screenwriter":
Intent intent = new Intent(getApplicationContext(),HomeScreenwriter.class);
intent.putExtra("user",user);
startActivity(intent);
case "Producer":
Intent intentP = new Intent(getApplicationContext(),HomeProducer.class);
intentP.putExtra("user",user);
startActivity(intentP);
case "Scenograph":
Intent intentSp = new Intent(getApplicationContext(),HomeScenograph.class);
intentSp.putExtra("user",user);
startActivity(intentSp);
default:
Toast.makeText(Register.this, "Invalid job.",
Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(Register.this, "User null", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(Register.this, databaseError.getMessage(),
Toast.LENGTH_LONG).show();
}
});
I created the User object like that, because trying to recieve it directly from Firebase gives me a null object and I don't really know why.
Saving the user in the Realtime Database is the work of this function, which I called right before the listener:
private void writeNewUser( String email, String password, String job) {
User user = new User(email, password, job);
myRef.setValue(user);
}
Is it wrong to create a user with other attributes except email and password? In the Firebase documentation I only see examples using these two fields, but I really need to separate the users with that attribute, because I'm developing something different for each of them.
Thank you in advance!