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());
}
}
});
"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());
}
}
});
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
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.