【发布时间】:2018-06-07 00:57:37
【问题描述】:
是因为权限吗?
我在运行时授予了READ_SMS , RECEIVE_SMS, READ_PHONE_STATE 权限,但它仍然崩溃。
12-26 10:56:02.409 30698-30698/? E/UncaughtException: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=55, result=0, data=null} to activity {com.app.eco4ndly.pathshala/com.app.eco4ndly.pathshala.Opening_Screen}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4255)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4298)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6339)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
at com.app.eco4ndly.pathshala.Opening_Screen.onActivityResult(Opening_Screen.java:108)
at android.app.Activity.dispatchActivityResult(Activity.java:6948)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4251)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4298)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6339)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
还需要做什么?
更新
在 Openning_Screen.java
中private void attemptsRegistration() {
Intent intent = new Intent(Opening_Screen.this,PhoneVerification.class);
intent.putExtra(Constant.REQUEST_CODE,55);
startActivityForResult(intent,55);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
final View view = findViewById(android.R.id.content);
if (requestCode == 55){
String result = data.getStringExtra("result");
if (result.equals("PhoneVerifiedSuccessfully")){
RegistrationDataPass.setPhone(data.getStringExtra("phone"));
Intent i = new Intent(Opening_Screen.this,RegPage1.class);
i.putExtra("PhoneNumber",data.getStringExtra("phone"));
startActivity(i);
}else if (result.equals("InvalidCode")){
Constant.showSnak(view,"Registration Failed\nInvalid Code");
}else if (result.equals("INVALID REQUEST")){
Constant.showSnak(view,"Registration Failed\nINVALID REQUEST");
}else if (result.equals("Too many Request")){
Constant.showSnak(view,"Registration Failed\nToo many Requests");
}
}
}
Phone_Verification.java 代码很大,我正在解释它是如何工作的。
当它开始时,我正在检查 marshmallow 的权限,然后在授予所有权限后,电话号码将作为用户的输入,然后转到 verifyPhone()
public void verifyPhone(String phn, PhoneAuthProvider.OnVerificationStateChangedCallbacks _mCallbacks){
mCallbacksResend = _mCallbacks;
Constant.showProgressBar(this,"You will receive an OTP in "+phn);
Log.e("STEP Inside ver pn",phn);
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phn, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
_mCallbacks); // OnVerificationStateChangedCallback
}
而验证回调是这样的
final PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallBacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
//progressDialog.dismiss();
Log.d("JEJE", "onVerificationCompleted:" + phoneAuthCredential);
Log.e("STEP in signin","InsideVerification");
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Constant.hideProgressBar();
Log.w("JEJE", "onVerificationFailed", e);
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Log.d("JEJE", "INVALID REQUEST");
Intent intent = new Intent();
intent.putExtra("result","INVALID REQUEST");
intent.putExtra("phone",phoneNumber);
setResult(REQ_CODE,intent);
} else if (e instanceof FirebaseTooManyRequestsException) {
Log.d("JEJE", "Too many Request");
Intent intent = new Intent();
intent.putExtra("result","Too many Request");
intent.putExtra("phone",phoneNumber);
setResult(REQ_CODE,intent);
}
showSnakBar(e.toString());
//hideProgressDialog();
Constant.hideProgressBar();
Toast.makeText(PhoneVerification.this, "Failed", Toast.LENGTH_SHORT).show();
finish();
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
//hideProgressDialog();
Constant.hideProgressBar();
Log.d("JEJE", "onCodeSent:" + s);
mResendToken = forceResendingToken;
tv.setText("We have sent a verification Code to your number "+phoneNumber+" via SMS.\nEnter the CODE bellow");
phoneNumLayout.setVisibility(View.GONE);
otpLayout.setVisibility(View.VISIBLE);
verifyToken = s;
showTimer();
}
};
在verifyPhone() 中显示进度条后应用程序崩溃。未发送任何代码。
【问题讨论】:
-
分享相关代码
-
您确定此错误与版本有关吗?
-
是
NullPointerException。发布您的Opening_Screen.java文件。 -
@Nilu 不,不是。幸运的是,我知道 NullPointerException 是什么。
-
@Xenolion 你是对的。此错误与版本无关。我弄错了
标签: android firebase-authentication android-permissions