我正在使用此代码从解析云中获取一行,但每次我获取对象时,它都会给我空列表,虽然解析中有相应的行可供我查找和更新。
public void onClick(View v) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("StudentInfo");
query.whereEqualTo("rollnum",rollnum.getText().toString());
query.whereEqualTo("name",name.getText().toString());
query.whereEqualTo("city",city.getText().toString());
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if(e == null && objects.size() > 0){
obj=objects.get(0);
obj.put("rollnum",rollnum.getText()
.toString());
obj.put("name",name.getText().toString());
obj.put("city", city.getText().toString());
obj.saveInBackground();
}
else if(objects.size()==0){
Toast.makeText(getApplicationContext(), "No relation Found!"+e,Toast.LENGTH_LONG).show();
}
}
}
如果对象在那里我在put方法的帮助下用新值更新它。但是它总是给我一个空的Parse Objects列表。
答案 0 :(得分:0)
我认为您正在尝试更新可用对象。您可以这样做。
public void onClick(View v) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("StudentInfo");
query.whereEqualTo("rollnum",rollnum.getText().toString());
query.whereEqualTo("name",name.getText().toString());
query.whereEqualTo("city",city.getText().toString());
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if(e == null ){
if(object.size()==0){
//here you can put object with help of put method if object is not there and when the object size is greater than 1 you remove the other objects except the objects.get(0).All other objects except one will be removed and only the zeroth object will be updated at the time user updates it
}
else if( objects.size() > 0){
obj=objects.get(0);
obj.put("rollnum",rollnum.getText()
.toString());
obj.put("name",name.getText().toString());
obj.put("city", city.getText().toString());
obj.saveInBackground();
}
}
else{
//exception in getting data
}
}
}
答案 1 :(得分:0)
如果您获得一个空的对象列表,那么这意味着没有存储的对象符合您要查询的条件。
确保您了解您的查询。在设置查询的方式中,必须存储一个ParseObject,其中rollnum,name和city等于您要测试的值,并且它们必须完全相等。如果没有对象匹配该条件,则解析将返回一个空列表。使用Logcat和Parse Dashboard进行调试,找出查询的错误。