[英]Android: ParseUser.getCurrentUser() returning empty object even after Logout
In my Android code i am checking the condition on parse current user. 在我的Android代码中,我正在检查解析当前用户的条件。 if user is logged in them some action is performing and if not other action is performing. 如果用户已登录,则他们正在执行某些操作,如果没有执行其他操作。 but when i am checking the condition even after user is logged out the ParseUser.getCurrentUser() is returning object, when i am trying to access data via parseCurrentUserObject the app is crashing, getting either NullpointerException or IllegalStateException. 但是当我即使在用户注销后也要检查条件时,ParseUser.getCurrentUser()返回对象时,当我尝试通过parseCurrentUserObject访问数据时,应用程序崩溃了,获取了NullpointerException或IllegalStateException。
i also gone through the link Parse for Android : ParseUser.logOut() doesn't log user out but din't workout for me. 我还通过了Android的Parse链接:ParseUser.logOut()不会注销用户,但对我而言不是锻炼。
code is - 代码是-
` `
ParseUser.logOut();
if (ParseUser.getCurrentUser() != null) {
Log.d("userType: ", ParseUser.getCurrentUser().getString("userType")
.toString());
tabSettingForPrivateUser(rootView);
} else {
tabSettingForPublicUser(rootView);
}
` `
app is crashing at log message where i am trying to access data from object: 应用程序在日志消息中崩溃,我正在尝试从对象访问数据:
Log.d("userType: ", ParseUser.getCurrentUser().getString("userType").toString());
LogCat error message at this line - 此行的LogCat错误消息-
08-15 17:58:05.250: E/AndroidRuntime(1220): Caused by: java.lang.NullPointerException
How to deal with this problem ? 如何解决这个问题?
The documentation very clearly says: 该文档非常清楚地说:
public static void logOut()
Logs out the currently logged in user session. 注销当前登录的用户会话。 This will remove the session from disk, log out of linked services, and future calls to ParseUser.getCurrentUser() will return null. 这将从磁盘中删除会话,注销链接的服务,以后对ParseUser.getCurrentUser()的调用将返回null。
If the method call to ParseUser.getCurrentUser()
does not behave as expected, then this is a bug in the API. 如果对ParseUser.getCurrentUser()
的方法调用ParseUser.getCurrentUser()
预期方式运行,则这是API中的错误。
Have you tried using the debugger and setting a breakpoint to see what variables are null when your app crashes? 您是否尝试过使用调试器并设置断点以查看应用崩溃时哪些变量为null? Are you sure that the String
you are getting isn't null? 您确定要获取的String
不为null吗?
Also, you are using a key to access the value in the ParseObject
. 另外,您正在使用键来访问ParseObject
的值。 It is definitely a good idea to keep the keys centralized in an interface
. 将密钥集中在interface
绝对是一个好主意。 Makes debugging a lot easier and the code more maintainable. 使调试更加容易,代码更易于维护。 Writing the raw string value for the key is definitely a recipe for disaster. 为密钥写原始字符串值绝对是灾难的秘诀。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.