par*_*rth 0 android parse-platform
我的表"Attack"中有2个指针对象(指向ParseUser).看起来这些指针对象需要一段时间才能被检索.因为我的代码直接没有用,并且给了我异常:
java.lang.IllegalStateException: ParseObject has no data for this key. Call fetchIfNeeded() to get the data.
Run Code Online (Sandbox Code Playgroud)
然后,我使用try-catch块对fetchIfNeeded函数进行了必要的操作:
ParseObject battle = null;
try {
battle = objects.get(0).fetchIfNeeded();
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ParseUser attacker1 = battle.getParseUser("Attacker");
Log.i("dontest",attacker1.getUsername());
Run Code Online (Sandbox Code Playgroud)
它仍然返回相同.我甚至检查isDataAvailable功能,它返回true.Any方式围绕这个?
PS:我的查询返回了我用size()函数检查的1行.
这是描述fetchIfNeeded()函数的文档.
像这样使用您的查询..
ParseQuery<ParseObject> pQueryFromAttack = new ParseQuery<ParseObject>("Attack");
// use include to fetch details while quering----increase loading speed by doing this.
pQueryFromAttack.include("pointer to _user table");
List<ParseObject> listObj = pQueryFromAttack.find();
Run Code Online (Sandbox Code Playgroud)
例如:
String userName =listObj.get(0).fetchIfNeeded().getString("name");
Run Code Online (Sandbox Code Playgroud)
像这样用它......