我试图解决它,但我无法做任何事情,我总是得到NPE即使尝试和捕获,我不知道还有什么要做,请一些帮助,
删除npe的正确方法是什么?我该怎么办?
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() );
}
当我删除进度条时程序被执行但后来我在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
答案 0 :(得分:0)
在这种情况下尝试捕获会阻止您的应用程序崩溃。这只是一个Lint警告。
如果要删除警告。首先检查变量user
是否为空。
if (user == null){
// show error
return;
}
// your code
答案 1 :(得分:0)
在调用isEmailverified之前检查用户。用户可能为null,因此当您尝试在null上调用一个方法时,编译器将通过空指针异常。
尝试if(user!= Null和user.isEmailVerified)
答案 2 :(得分:0)
如果您使用mAuth记录用户,可以尝试
{
"First": [
0,
0
]
}
或
# Re-convert: $tempObj.First then *directly* contains the input array
# (there is no .Value property anymore).
$tempObj = $json | ConvertFrom-Json
# Construct a new hashtable...
$List2 = @{ First = $tempObj.First }
# ... and convert it to JSON.
$List2 | ConvertTo-Json
在您要求方法if(mAuth.getCurrentUser() != null) {
//do your stuff
if(user.isEmailVerified()){ ...}
}
之前
因此,您可以保证在请求用户信息之前已连接用户