1

When i call Parse method getList("some column") i always get NullPointerException. What should i do to avoid it? Here is some code

ParseObject someObj = new ParseObject("Some table");
someObj.put("some column", "some text");
someObj.saveInBackground();

List<String> someList = someObj.getList("some column");
Toast.makeText(getApplicationContext(), someList.get(0), Toast.LENGHT_LONG).show()
6
  • Could you post your ParceObject code ? Commented Dec 20, 2014 at 23:12
  • ParceObject is class from library. See on Parce.com Commented Dec 20, 2014 at 23:12
  • parce.com is unreachable i think you mean't parse.com, if so the class name is ParseObject and not ParceObject. Commented Dec 20, 2014 at 23:18
  • Sorry, it's my mistake. Parse.com Commented Dec 20, 2014 at 23:20
  • 1
    If there are spelling errors in the code in your question, that suggests you copied it by hand, instead of copy/pasting. That's not a very good idea: it makes errors more likely, and errors make it hard to help you. Commented Dec 20, 2014 at 23:28

1 Answer 1

2

I think that you're not getting a NPE in List<String> someList = someObj.getList("some column"); I think that getList is returning null and you're getting the NPE when you try to get the first element on this list in the follow line: someList.get(0).

In ParseObject api for android:

getList returns null if there is no such key or if the value can't be converted to a List

So since you're setting a string some text value for some column key in someObj.put("some column", "some text"), you can't get this value as List using getList("some column"), so simply use get("some column") instead.

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

2 Comments

No, someList.get(0) would throw an IndexOutOfBoundsException if it had size 0.
@pbabcdefp getList not returns a list of size 0, returns null, so get(0) on null object throws NullPointerException not IndexOutOfBoundsException.

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.