我正在使用此代码实际让用户发送问题和4个答案(这是一个很长的故事),并将其存储在我的游戏数据库中。这是我看到文档后使用的代码,只是表格没有更新。我真的不知道为什么
private void sendQuestion() {
ParseUser currentUser = ParseUser.getCurrentUser();
String role = currentUser.get("Role").toString();
if(role.equals("Founder"))
{
String questionText = mQuestion.getText().toString();
String[] answers = new String[4];
for(int i = 0; i < 4; i++) {
answers[i] = mAnswers[i].getText().toString();
}
ParseObject question = new ParseObject("Questions");
question.put("lang", mSelectedLang);
question.put("question", questionText);
for(int i = 0; i < 4; i++) question.put("answer" + (i+1), answers[i]);
question.put("enabled", true);
question.put("from", currentUser);
question.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
Log.d("MyApp", "Done");
}
});
}else
Log.d("MyApp", "Not founder");
}
这是我从日志
获得的05-27 19:57:21.063 2307-2307/*************** D/MyApp﹕ Send question button pressed
05-27 19:57:21.530 2307-2307/*************** D/MyApp﹕ Done
表示它已经完成,但表格问题没有更新,如上所述。注意“lang”和“from”都是关系字段,所以我把对象放在那里,而不是像字符串或整数这样的简单值。
为什么表格没有更新?
在这里,您可以查看保存对象https://www.parse.com/docs/android/guide#objects-saving-objects
的官方文档答案 0 :(得分:1)
我自行解决了从&#39;关系&#39;更改行类型的问题。到了指针&#39;,正如我在这里阅读https://parse.com/questions/expected-relation_user-but-got-_user(没有找到它,因为它被要求提供iOS,但它不是关于错误的代码)。
现在可行。
答案 1 :(得分:0)
我认为你应该改变
question.put("from", currentUser);
有类似的东西:
question.put("from", currentUser.getId()); // pass id of user, not object itself