0

This is doing my head in. I got this working in iOS in about 10 mins. Clearly I'm missing something. I'm simply trying to pull data out of parse.com into a textfield. I have found lots of examples but none explaining why it's not working correctly. Below is the code pulled from parse.com site and jiggyed with. Incidentally it's wigging out on totemList.getString particularly the "getString" part.

 ParseQuery<ParseObject> query = ParseQuery.getQuery("Birds");
           query.whereEqualTo("totemName", "Pigeon");
           query.findInBackground(new FindCallback<ParseObject>() {
               public void done(List<ParseObject> totemList, ParseException e) {
                   if (e == null) {
                       Log.d("score", "Retrieved " + totemList.size() + " scores");
                       String totemDesc = totemList.getString("totemDesc");
                       //Get the Totems Description
                       TotemDescription = (TextView)findViewById(R.id.animalDesc);
                       TotemDescription.setText(totemDesc);
                   } else {
                       Log.d("score", "Error: " + e.getMessage());
                       // something went wrong
                       TotemDescription = (TextView)findViewById(R.id.animalDesc);
                       TotemDescription.setText("not bob");
                   }
               }
           });
5
  • What's the error you're getting? Commented Aug 8, 2013 at 5:50
  • cannot resolve method 'getString(java.lang.String); Commented Aug 8, 2013 at 5:52
  • BTW hector this is directly off of the parse.com site and no animals were harmed in coding this... Commented Aug 8, 2013 at 6:32
  • Can you post a link to the specific doc that has this code sample? Commented Aug 8, 2013 at 17:14
  • Hi Hector, no worries. It's in the Docs section saving objects( "retrieve objects" parse.com/docs/android_guide. The only thing I changed was clearly the table I was hiding and "findInBackground" rather then "getInBackground". HTH. I'm about to attempt to pull an image out of parse for android now...no doubt I will be back with more questions..hehe Commented Aug 8, 2013 at 23:38

1 Answer 1

3

List<> does not have a getString() method.

List<ParseObject> totemList

Perhaps what you wanted to do was to iterate over your list of ParseObject get all the descriptions:

String descriptions = null;
for (ParseObject totem : totemList) {
    if (descriptions == null) {
        descriptions = totem.getString("totemDesc");
    } else {
        descriptions = descriptions + ", " + totem.getString("totemDesc");
    }
} 

Something like that. Then set the resulting string as text of your text field

TotemDescription.setText(descriptions); 

If you have more than one ParseObject in your List<> your text will be something like:

Pigeon Totem, Another Pigeon Totem
Sign up to request clarification or add additional context in comments.

9 Comments

Hi Marat, I just read that as your answer came up. Why would they use it on the example site if that were not the case? If List<> should not be used what should be? In iOS it's a Simple PFObject then you just ask the object for the specific attribute you want. i.e. out of the row of data give me the "name" or give me the "description".
Well a List<> is just an ordered collection of elements - in your case ParseObject. Seems like what the callback gives you is a collection of these elements, and you can call getString("totemDesc") on each one to get your descriptions.
So you mean calling it directly in the TextView call? Is this what you mean? Do you have an example of what your suggesting?
Makes logical sense to me the way you suggested but still crashed. Only this time didn't give me any warnings...
Take a look at your LogCat output to see where the crash/problem is, and go on from there. Unfortunately I can't really tell you much more without having further insight into your project, and what the crash is.
|

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.