2

I don't know what's wrong with my code, that it always returns null when I use getParseObject().

I'm using parse.com to save my data, and in one table I used one file as a pointer. I have a Game class that has ImgName as a Pointer<Gallery> to a gallery class.

Now I want to retrieve the ImgName value, so this is what I did:

public Adapter(Context context) {
    super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() {
        public ParseQuery create() {
            ParseQuery query = new ParseQuery("Game");
            query.include("ImgName");
            return query;
        }
    });
}

// Customize the layout by overriding getItemView
@Override
public View getItemView(final ParseObject object, View v, ViewGroup parent) {

    if (v == null) {
        v = View.inflate(getContext(), R.layout.list_item_landing_cards, null);
    }
    ParseObject gallery =  object.getParseObject("ImgName");
    String name=gallery.getString("name");
    TextView nameTextView = (TextView) v.findViewById(R.id.text);
    nameTextView.setText(name);

But I'm getting null all the time. Any suggestions?

8
  • Object is a newly created parseobject, how to you expect getparseobject to return anything other than null? Commented Jul 29, 2015 at 13:26
  • I updated the code , still giving me null ... please tell me what's wrong Commented Jul 29, 2015 at 13:32
  • The updated code looks more correct. Are you sure that all of your game objects has a pointer in the "ImgName" column? Commented Jul 29, 2015 at 17:07
  • Could you verify that the column name is correct and that it has a value... Commented Jul 30, 2015 at 22:20
  • 1
    Yes, that could be a cell reuse issue. Have a check to see if the value is null and then set values accordingly. Commented Jul 31, 2015 at 20:40

1 Answer 1

1

Use this for the re-use issue:

ParseObject gallery =  object.getParseObject("ImgName");
if (gallery != null) {
    String name=gallery.getString("name");
    TextView nameTextView = (TextView) v.findViewById(R.id.text);
    nameTextView.setText(name);
} else {
    nameTextView.setText(""); // or any other default value you want to set
}

NOTE: The cell re-use issue is not on Parse. Cell re-use is a general concept used by the ListView. The cells are recycled for performance by Android. We just have to protect it from re-using old values.

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

2 Comments

Thanks .. do you any prove that there is re-use issue in parse ? I searched but I couldn't find
No, it's not an issue with Parse. See update to my answer.

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.