问题
I'm getting this error:
E/AndroidRuntime: Error reporting crash android.os.TransactionTooLargeException
and this too:
java.lang.StackOverflowError: stack size 8MB
while running below given code:
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
final FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
if (isFacebookLoggedIn()) {
if (dialog == null) {
final AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this);
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View alertDialogView = inflater.inflate(R.layout.choose_unique_name_dialog, null);
uniqueUserName = (EditText) alertDialogView.findViewById(R.id.uniqueUserName);
usernameChoosen = (TextView) alertDialogView.findViewById(R.id.usernameChoosen);
usernameWarning = (TextView) alertDialogView.findViewById(R.id.usernameWarning);
usernameChoosen.setVisibility(View.INVISIBLE);
usernameWarning.setVisibility(View.INVISIBLE);
builder.setTitle("Choose a unique username");
builder.setView(alertDialogView);
builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
dialog = builder.create();
}
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
wantToCloseDialog = false;
//Do stuff, possibly set wantToCloseDialog to true then...
if (uniqueUserName.getText().toString().isEmpty()) {
Toast.makeText(getBaseContext(), "Please choose a unique username", Toast.LENGTH_LONG).show();
wantToCloseDialog = false;
} else {
mDatabase.child("unique-usernames").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.getValue() != null) {
if (dataSnapshot.getValue().toString().contains(uniqueUserName.getText().toString())) {
Toast.makeText(getBaseContext(), uniqueUserName.getText().toString() + " is already taken", Toast.LENGTH_LONG).show();
usernameChoosen.setText(uniqueUserName.getText().toString());
wantToCloseDialog = false;
} else {
// error is happening on execution of this code
Log.d("signedIn", "onAuthStateChanged:signed_in:" + user.getUid());
mDatabase.child("users").child(user.getUid()).child("name").setValue(user.getDisplayName());
mDatabase.child("users").child(user.getUid()).child("imageUID").setValue(user.getPhotoUrl());
mDatabase.child("users").child(user.getUid()).child("uniqueUserName").setValue(uniqueUserName.getText().toString());
mDatabase.child("users").child(user.getUid()).child("followers").setValue("00");
mDatabase.child("users").child(user.getUid()).child("following").setValue("00");
mDatabase.child("unique-usernames").child(ts).setValue(uniqueUserName.getText().toString());
Intent mainIntent = new Intent(SignUpActivity.this, SplashActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
progressDialog.setMessage("Signing up...");
progressDialog.setCancelable(false);
progressDialog.show();
wantToCloseDialog = true;
}
} else {
Log.d("signedIn", "onAuthStateChanged:signed_in:" + user.getUid());
mDatabase.child("users").child(user.getUid()).child("name").setValue(user.getDisplayName());
mDatabase.child("users").child(user.getUid()).child("imageUID").setValue(user.getPhotoUrl());
mDatabase.child("users").child(user.getUid()).child("uniqueUserName").setValue(uniqueUserName.getText().toString());
mDatabase.child("users").child(user.getUid()).child("followers").setValue("00");
mDatabase.child("users").child(user.getUid()).child("following").setValue("00");
mDatabase.child("unique-usernames").child(ts).setValue(uniqueUserName.getText().toString());
Intent mainIntent = new Intent(SignUpActivity.this, SplashActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
progressDialog.setMessage("Signing up...");
progressDialog.setCancelable(false);
progressDialog.show();
wantToCloseDialog = true;
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Snackbar snackbar = Snackbar
.make(coordinatorLayout, databaseError.getMessage(), Snackbar.LENGTH_LONG);
snackbar.show();
wantToCloseDialog = false;
}
});
}
if(wantToCloseDialog)
dialog.dismiss();
//else dialog stays open. Make sure you have an obvious way to close the dialog especially if you set cancellable to false.
}
});
} else {
Log.d("signedIn", "onAuthStateChanged:signed_in:" + user.getUid());
mDatabase.child("users").child(user.getUid()).child("name").setValue(userName.getText().toString());
mDatabase.child("users").child(user.getUid()).child("uniqueUserName").setValue(uniqueUserName.getText().toString());
mDatabase.child("users").child(user.getUid()).child("followers").setValue("00");
mDatabase.child("users").child(user.getUid()).child("following").setValue("00");
mDatabase.child("unique-usernames").child(ts).setValue(uniqueUserName.getText().toString());
Intent mainIntent = new Intent(SignUpActivity.this, SplashActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
progressDialog.dismiss();
}
} else {
// User is signed out
Log.d("signedOut", "onAuthStateChanged:signed_out");
}
// ...
}
};
I have never seen any such error before and that's why I have no idea what's happening here.
Please let me know what is causing this error!
回答1:
After looking deeply into code at least 10-12 times, I got the problem here.
The solution was to add .toString()
with user.getPhotoUrl()
in this line of code: mDatabase.child("users").child(user.getUid()).child("imageUID").setValue(user.getPhotoUrl());
This answer here gave me a bit hint. Thanks qbix.
So, it has been solved now!
回答2:
You are adding a listener for node mDatabase.child("unique-usernames")
. Then in the onDataChange()
callback for that listener, you are modifying a child of that same node:
mDatabase.child("unique-usernames").child(ts).setValue(uniqueUserName.getText().toString());
This causes the listener callback to fire again, resulting in an endless loop.
来源:https://stackoverflow.com/questions/40661629/getting-e-androidruntime-error-reporting-crash-android-os-transactiontoolargee