我已经在我的桌面上安装了示例解析服务器 ( https://github.com/ParsePlatform/parse-server-example ) 并制作了一个简单的应用程序来测试它。
我的应用程序将一个对象保存到服务器,获取该对象并将 mTextView 的值设置为我的对象的值。
问题是,当我尝试使用此代码从服务器获取数据时,它可以工作:
query.getInBackground("5K7N8a8Dmd", new GetCallback<ParseObject>() ...
(通过 curl 获取对象 ID)
但是当我尝试这个时(使用curl获取对象ID):
gameScore.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
objectId = gameScore.getObjectId();
} else {
Log.e("saveInBackground", getErrorMessage(e));
}
}
});
...
query.getInBackground(objectId, new GetCallback<ParseObject>() ...
它不起作用。
日志猫:
E/getInBackground﹕ no results found for query - code: 101
MainActivity.java
public class MainActivity extends Activity {
public TextView mTextView;
public String objectId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.text_view);
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId(Constants.APP_ID)
.server(Constants.SERVER_URL)
.build()
);
final ParseObject gameScore = new ParseObject("Foo1234");
gameScore.put("score", 5000);
gameScore.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
objectId = gameScore.getObjectId();
} else {
Log.e("saveInBackground", getErrorMessage(e));
}
}
});
ParseQuery<ParseObject> query = ParseQuery.getQuery("Foo1234");
query.getInBackground(objectId, new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
mTextView.setText(Integer.toString(gameScore.getInt("score")));
} else {
Log.e("getInBackground", getErrorMessage(e));
}
}
});
}
public String getErrorMessage(ParseException e) {
return e.getMessage() + " - code: " + e.getCode();
}
}
常量.java
public class Constants {
public static String SERVER_URL = "http://192.168.1.14:1337/parse/";
public static String APP_ID = "myAppId";
}
提前致谢。