简体   繁体   中英

NullPointerException while using Parse

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()

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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM