1

I may not be understanding the subtleties of the ParseUser but from what I can tell, ParseUser objects inherit the .getString method. In my program, I am trying to retrieve a string from the "screenName" field of my ParseUser object. I have used this line:

ParseUser currentUser = ParseUser.getCurrentUser();

to retrieve the current user object, and I am trying to access the screenName field as such:

String screenNameString = (String) currentUser.get("screenName");

This returns null to the screenNameString and I'm not sure why. I have checked that the currentUser has grabbed the right user object (I can see the correct username and ObjectID).

The goal of this code is to eventually grab the screenName field of the current user and write it into a TextView. Here is the rest of my code in case that reveals any more issues.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);

    // grab current user
    ParseUser currentUser = ParseUser.getCurrentUser();

    // TODO implement call backs for each field
    // TODO this doesn't work :( look up ParseUser methods for grabbing stuff
    if (currentUser != null) {
        /* Set user specific views*/
        // Set screenName
        TextView screenNameTextView = (TextView) findViewById(R.id.screenName);
        String screenNameString = (String) currentUser.get("screenName");
        screenNameTextView.setText(screenNameString);

        // Set bio
        TextView bioTextView = (TextView) findViewById(R.id.bio);
        String bioString = (String) currentUser.get("bio");
        bioTextView.setText(bioString);

    } else {
        // Error log
        Log.e("ProfileActivity", "could not locate CurrentUser");
    }
}

This is the onCreate method for an activity which shows the user their profile in my app. Notice there is also a "bio" field I'm trying to grab. This is giving me the same problem. I have added both of the fields as columns of the ParseUser in my Parse data dashboard. If anyone has any advice or help I would really appreciate it! Thanks!

0

1 Answer 1

1

try to call fetchInBackground() and then try to get these values. Also you don't need to cast these values to String - you can use getString() method explicitly.

Sign up to request clarification or add additional context in comments.

2 Comments

Ahh I see, so would a good strategy be to do a fetch in background then set the text in a callback using the object it finds? Still getting used to Parse but that's what I would think.
Works perfectly! I'll have to make it a habit to use the callback. Thank you Oleg!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.