[英]NullPointerException while using Parse
When i call Parse
method getList("some column") i always get NullPointerException
. 当我调用
Parse
方法getList(“ some column”)时,我总是得到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");
我认为您没有在
List<String> someList = someObj.getList("some column");
获得NPE
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)
. 我认为
getList
返回null
,当您尝试在以下行中获取此列表中的第一个元素时,您将获得NPE
: someList.get(0)
。
In ParseObject
api for android: 在适用于Android的
ParseObject
api中:
getList
returns null if there is no such key or if the value can't be converted to a List如果没有这样的键或无法将值转换为List,则
getList
返回null
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. 因此,由于您要为
someObj.put("some column", "some text")
some column
键设置字符串some text
值,因此无法使用getList("some column")
将此值作为List
获得,因此只需使用get("some column")
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.