我目前正在使用Firebase Real-time DB处理我的项目,但是当我执行它给我的方法时,我遇到了一个问题:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: naufal.com.tugasakhir, PID: 7291
java.lang.IllegalArgumentException: Given String is empty or null
at com.google.android.gms.common.internal.zzaa.zzdl(Unknown Source)
at com.google.firebase.auth.FirebaseUser.updatePassword(Unknown Source)
at naufal.com.tugasakhir.ChangePass$1.onClick(ChangePass.java:59)
at android.view.View.performClick(View.java:5246)
at android.widget.TextView.performClick(TextView.java:10620)
at android.view.View$PerformClick.run(View.java:21256)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6934)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
这是我的updatePassword()方法
mUser.updatePassword(repass).addOnCompleteListener(ChangePass.this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (!task.isSuccessful()) {
Toast.makeText(ChangePass.this, "Update Password Failed",
Toast.LENGTH_SHORT).show();
} else {
startActivity(new Intent(ChangePass.this, MainActivity.class));
finish();
}
}
});
这是我的getCurrentUser()对象初始化
final FirebaseUser mUser = FirebaseAuth.getInstance().getCurrentUser();
该对象超出了onCreate()方法,因此必须使用final。
package naufal.com.tugasakhir;
import android.content.Intent;
import android.nfc.Tag;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.firebase.client.Firebase;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class ChangePass extends AppCompatActivity {
private EditText mChangepass,mReChangePass;
private Button mChangeBtn;
private static final String TAG = ChangePass.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_change_pass);
mChangepass = (EditText) findViewById(R.id.changePass);
mReChangePass = (EditText) findViewById(R.id.reChangePass);
mChangeBtn = (Button) findViewById(R.id.changeBtn);
final FirebaseUser mUser = FirebaseAuth.getInstance().getCurrentUser();
mChangeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String pass = mChangepass.getText().toString().trim();
String repass = mReChangePass.getText().toString().trim();
if(pass.isEmpty()){
Toast.makeText(getApplicationContext(), "Enter New Password", Toast.LENGTH_SHORT).show();
}
if(repass.isEmpty()){
Toast.makeText(getApplicationContext(), "Enter New Password", Toast.LENGTH_SHORT).show();
}
if(pass.length()<6){
Toast.makeText(getApplicationContext(), "Password is too Short (Minimum 6)", Toast.LENGTH_SHORT).show();
}
if(!pass.equals(repass)){
Toast.makeText(getApplicationContext(), "Password Does Not Match", Toast.LENGTH_SHORT).show();
}
assert mUser != null;
mUser.updatePassword(repass).addOnCompleteListener(ChangePass.this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (!task.isSuccessful()) {
Toast.makeText(ChangePass.this, "Update Password Failed",
Toast.LENGTH_SHORT).show();
} else {
startActivity(new Intent(ChangePass.this, MainActivity.class));
finish();
}
}
});
});
}
}
谢谢你的回复。