我正在使用Firebase注册用户,用户可以更新其数据,但是在更新电子邮件时,他们总是向我发送任务失败的响应,并且我验证了在更新电子邮件时它写得很好。 这是代码:
`private String vPassword, vEmail;
private Button btnValidate;
private EditText edContra, edEmail;
private TextView errorContra;
private ProgressDialog pDialog;
String sMail;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_pop_reset_email);
pDialog = new ProgressDialog (this);
vPassword = getIntent (). getStringExtra ("password");
vEmail = getIntent (). getStringExtra ("email");
btnValidar = findViewById (R.id.btnValidar);
edContra = findViewById (R.id.passwordValidate);
edEmail = findViewById (R.id.correoValidar);
errorContra = findViewById (R.id.errorContraValidar);
DisplayMetrics measures = new DisplayMetrics ();
getWindowManager (). getDefaultDisplay (). getMetrics (measures);
int width = measurements.widthPixels;
int high = measures.heightPixels;
getWindow (). setLayout ((int) (width * 0.85), (int) (height * 0.5));
btnValidar.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick (View view) {
String edPassword = edContra.getText (). ToString ();
sMail = edEmail.getText (). toString ();
if (edPassword.equals (vPassword)) {
Verify ();
} else {
errorContra.setVisibility (View.VISIBLE);
}
}
});
}
// CHECK EMAIL
private void Verify () {
if (! sCorreo.isEmpty () && sCorreo.contains ("@") && sCorreo.contains (".")) {
errorContra.setVisibility (View.INVISIBLE);
pDialog.setMessage ("Updating ...");
pDialog.setCanceledOnTouchOutside (false);
pDialog.show ();
UpdateMail ();
} else {
errorContra.setVisibility (View.VISIBLE);
errorContra.setText ("* Type Valid Mail.");
}
}
// UPDATE EMAIL
private void UpdateMail () {
FirebaseUser user = FirebaseAuth.getInstance (). GetCurrentUser ();
user.updateEmail (sMail) .addOnCompleteListener (new OnCompleteListener <Void> () {
@Override
public void onComplete (@NonNull Task <Void> task) {
if (task.isSuccessful ()) {
Toast.makeText (PopResetEmail.this, "Mail Updated", Toast.LENGTH_SHORT)
.show ();
} else {
Toast.makeText (PopResetEmail.this, "Email ERROR", Toast.LENGTH_SHORT)
.show();
}
pDialog.dismiss ();
}
});
}
// CLOSE ACTIVITY X
public void Close (View view) {
finish ();
}`
已经确认在邮件更新时,它是从编辑文本中获取并转换为字符串的。
在我按下按钮进行更新时在设备上进行测试时,该消息会显示在日志中:
2020-08-02 08:43:40.045 7910-7910/com.example.donmigue V/Toast: HANDLE HIDE:
android.widget.Toast$TN@adee711 mView=null
2020-08-02 08:43:40.071 7910-7910/com.example.donmigue
D/ViewRootImpl@c39e34d[Toast]: setView = android.widget.LinearLayout@375c076
TM=true MM=false
2020-08-02 08:43:40.071 7910-7910/com.example.donmigue V/Toast: Text: Dorr in
android.widget.Toast$TN@adee711
//THIS IS A MISTAKE------------------
2020-08-02 08:43:40.096 7910-7910/com.example.donmigue E/GraphicExt:
GraphicExtModuleLoader::CreateGraphicExtInstance false
//-----------------------------------
2020-08-02 08:43:40.097 7910-7910/com.example.donmigue
D/ViewRootImpl@c39e34d[Toast]: Relayout returned: old=(0,55,720,1436) new=
(230,714,490,791) req=(260,77)0 dur=19 res=0x7 s={true 3939788800} ch=true
2020-08-02 08:43:40.100 7910-7942/com.example.donmigue D/OpenGLRenderer:
createReliableSurface : 0xbaba46c0(0xead46800)
2020-08-02 08:43:40.106 7910-7942/com.example.donmigue D/OpenGLRenderer:
makeCurrent EglSurface : 0x0 -> 0xd6e49580
2020-08-02 08:43:40.109 7910-7942/com.example.donmigue I/GPUD:
@gpudInitialize:
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.110 7910-7942/com.example.donmigue I/GPUD:
@gpudInitialize:
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue
D/ViewRootImpl@630eeec[PopResetEmail]: MSG_WINDOW_FOCUS_CHANGED 1 1
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue D/InputMethodManager:
prepareNavigationBarInfo() DecorView@a03932b[PopResetEmail]
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue D/InputMethodManager:
getNavigationBarColor() -855310
//THIS IS A MISTAKE------------------
2020-08-02 08:43:40.134 7910-7910/com.example.donmigue E/ViewRootImpl:
sendUserActionEvent() mView returned.
//-----------------------------------
2020-08-02 08:43:40.138 7910-7942/com.example.donmigue D/OpenGLRenderer:
makeCurrent EglSurface : 0xd6e49580 -> 0xb8fc7640
2020-08-02 08:43:40.140 7910-7910/com.example.donmigue
D/ViewRootImpl@c39e34d[Toast]: MSG_RESIZED: frame=(230,714,490,791) ci=
(0,0,0,0)
vi=(0,0,260,77) or=1
2020-08-02 08:43:40.140 7910-7942/com.example.donmigue I/GPUD:
@gpudInitialize:
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.142 7910-7942/com.example.donmigue I/chatty:
uid=10536(com.example.donmigue) RenderThread identical 3 lines
答案 0 :(得分:1)
如果任务失败,则调用task.getException()
将为您提供有关发生问题的详细信息。因此,您需要使用类似的内容来显示/记录该信息:
user.updateEmail (sMail) .addOnCompleteListener (new OnCompleteListener <Void> () {
@Override
public void onComplete (@NonNull Task <Void> task) {
if (task.isSuccessful ()) {
Toast.makeText (PopResetEmail.this, "Mail Updated", Toast.LENGTH_SHORT).show ();
} else {
Exception e = task.getException();
Toast.makeText (PopResetEmail.this, "Error updating email: "+e.getMessage(), Toast.LENGTH_SHORT).show();
Log.w("updateEmail", "Unable to update email", e);
}
pDialog.dismiss ();
}
});
通常足以解决问题。
另请参阅: