我怎样才能解决这个问题?“方法调用'isEmailVerified'可能会产生'java.lang.NullPointerException'" [英] How can i fix this? "Method invocation 'isEmailVerified' may produce 'java.lang.NullPointerException'"
本文介绍了我怎样才能解决这个问题?“方法调用'isEmailVerified'可能会产生'java.lang.NullPointerException'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图解决它,但是我什么也做不了,即使尝试一试,我也总是得到NPE,我不知道该怎么办,请帮忙,
I tried to solve it but I can not do anything, I always get the NPE even with the try and catch, I do not know what else to do, please some help,
删除npe的正确方法是什么?我应该放什么?
what is the correct way to remove the npe? What should I put?
try{
if(user.isEmailVerified()){
Log.d(TAG, "onComplete: success. email is verified.");
Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
startActivity(intent);
} else {
Toast.makeText(mContext, "Email is not verified \n check your email inbox.", Toast.LENGTH_SHORT).show();
mProgressbar.setVisibility(View.GONE);
mPleaseWait.setVisibility(View.GONE);
mAuth.signOut();
}
} catch (NullPointerException e){
Log.e(TAG, "onComplete: NullPointerException: " + e.getMessage() );
}
当我删除进度条时,程序将被执行,但是随后我将所有这些都保存在日志中...
when I delete the progress bar the program is executed but then I get all this in the logcat...
02-18 21:03:17.670 1492-1492/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.togo.plgl.togo, PID: 1492
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.togo.plgl.togo/com.togo.plgl.togo.Home.HomeActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx.enableAnimation(boolean)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2793)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx.enableAnimation(boolean)' on a null object reference
at com.togo.plgl.togo.utils.BottomNavigationViewHelper.setupBottomNavigationView(BottomNavigationViewHelper.java:26)
at com.togo.plgl.togo.Home.HomeActivity.setupBottomNavigationView(HomeActivity.java:95)
at com.togo.plgl.togo.Home.HomeActivity.onCreate(HomeActivity.java:51)
at android.app.Activity.performCreate(Activity.java:6915)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
02-18 21:03:17.683 1492-1492/? I/Process: Sending signal. PID: 1492 SIG: 9
推荐答案
如果您正在使用mAuth记录用户,则可以尝试
If you are using mAuth to log your users you can try
if(mAuth.getCurrentUser() != null) {
//do your stuff
if(user.isEmailVerified()){ ...}
}
或
if(((mAuth.getCurrentUser() != null)&&(user.isEmailVerified()))) {
//do your stuff
Log.d(TAG, "onComplete: success. email is verified."); ....
}
在请求方法 isEmailVerified();
因此,您可以保证在与用户联系之前,先向他们请求信息
so you can guarantee that you have an user connected before requesting information from them
这篇关于我怎样才能解决这个问题?“方法调用'isEmailVerified'可能会产生'java.lang.NullPointerException'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文