简体   繁体   English

Android:即使注销后ParseUser.getCurrentUser()仍返回空对象

[英]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.

相关问题 在Android中检索ParseUser对象时遇到问题 - Trouble retrieving ParseUser Object in android 登录成功后,解析getCurrentUser()返回null - Parse getCurrentUser() is returning null after login successful ParseUser.logout()的不当行为 - Misbehaviour of ParseUser.logout() Android的ParseUser指示用户已登录,但无法从对象检索信息 - ParseUser Android indicates user is signed in but no information can be retrieved from object Android:即使数据库不为空,Cursor也始终返回null - Android: Cursor is always returning null even if the database is not empty android测试-EditText即使有字符也返回空 - android testing - EditText returning empty even when it has characters ParseUser.getCurrentUser.getList(“isFollowing”).add(users.get(p)) 和 ParseUser.getCurrentUser.add(“isFollowing”, users.get(p)) 之间的区别 - Difference between ParseUser.getCurrentUser.getList(“isFollowing”).add(users.get(p)) and ParseUser.getCurrentUser.add(“isFollowing”, users.get(p)) 即使字符串null或空检查后,Android Java异常 - Android Java exception even after string null or empty check 单例返回空对象 - Singleton returning empty Object Android Parse如何使用getObjectId(); 设置ParseUser对象时? - Android Parse how can I use getObjectId(); when setting a ParseUser object?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM