1

what I'm trying to do is querying a class and getting some strings. But the below code returns something like ;

com.parse.ParseObject@b4209180

and I couldn't get it to normal string value.

ParseQuery<ParseObject> query = ParseQuery.getQuery("question");
//query.whereKeyExists:@"objectId"
query.whereExists("questionTopic");

query.findInBackground(new FindCallback<ParseObject>() {

    @Override
    public void done(List<ParseObject> topics, ParseException e) {
        // TODO Auto-generated method stub
        if(e==null){


                textview.setText(topics.toString());

            }


        }else{
             Log.d("notretreive", "Error: " + e.getMessage());
        }


    }
});

3 Answers 3

1

"topics" in your code is a list of question objects. You need to get the topic from that object. This should get you on the way:

ParseQuery<ParseObject> query = ParseQuery.getQuery("question");
query.whereExists("questionTopic");

query.findInBackground(new FindCallback<ParseObject>() {

    @Override
    public void done(List<ParseObject> questions, ParseException e) {
        // The query returns a list of objects from the "questions" class
        if(e==null){
          for (ParseObject question : questions) {
            // Get the questionTopic value from the question object
            Log.d("question", "Topic: " + question.getString("questionTopic");
          }       
        } else {
             Log.d("notretreive", "Error: " + e.getMessage());
        }
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

from the API I can see that the class ParseObject Inherits toString() from Object class.

That means unless there is implementation of custom toString() it will return the human-readable description of this object.

check here for the toString() being called in your case

EDIT:

First of all you are trying to call toString() on List object by

topics.toString()

you will have to iterate over that List like

for(ParseObject parseObj : topics){
//do something with parseObj like
parseObj.get(<provide_key_here>);
//print to check the value
System.out.println(parseObj.get(<provide_key_here>));
//where key is generally attribute name
}

4 Comments

Thank You very much, but I couldn't understand the usage. If you can simply explain it I would be really thankful.
check my Edit, also refer androidbook.com/item/4458 and also learn Core Java Fundamentals, it will help you resolve such issues faster
I did everything you said. But the result is same :( and system.out.println doesn't returns anything. so I'm trying it with settext() .
question is the class name? in ParseQuery.getQuery("question");??\
0

I can see this is about two years old. But I am currently having the same issue. SO here is what I did.

You can't just call setText.toString because "topics" is returning as a Parse Object. You need to run a for loop to run through each topics object and get the text from that object, store it in a string and THEN you can set text to string. Here is what I did.

final List questions = new ArrayList<String>();

final ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("MasterQuestionList");
query.findInBackground(new FindCallback<ParseObject>() {
  public void done(List<ParseObject> Question, ParseException e) {
    if (e == null) {
      if (Question.size() > 0) {

        for (ParseObject user : Question) {

         String tFile = (String) user.get("Question");
          questions.add(tFile);

        }

        TextView a = (TextView) findViewById(R.id.sentence);
        a.setText(String.valueOf(questions));

I created a list, and added all text values to that list.

Hope this helps anyone running into a similar issue.

2 Comments

@clearlight, don't touch my comment. I can see from your profile that you raked in a gold badge by editing *500 or so posts. All you did was change my wording and formatted the post a bit. You offered no additional insight other than to get additional points for yourself. I rolled this back. Hope you see it. ~cheers
Your post was on a review queue for first post of new user. The goal there is to improve answers by editing, commenting, voting, flagging... I saw idiosyncratic formatting, and more intro than needed and trailing sentences that could be succinct and do better above the code. As for the points/badge accusation - you're confused... I already have the badge. You can only get one for editing posts. I do it to improve & clean up posts and I've helped a lot of users. It's weird because there are some red flags in what you've said & done that make you sound like you're not new here but only 1 rep

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.