Android 是否让Parse.com关系用户(从对象)访问Listview?

Android 是否让Parse.com关系用户(从对象)访问Listview?,android,listview,parse-platform,Android,Listview,Parse Platform,我在ParseObject中添加了一个与用户相关的关系,我想在listview中填充已添加到该关系的用户列表。这就是我目前所拥有的 protected List<ParseUser> mCustomers; ParseObject shopinfo= new ParseObject("Shopinfo"); // get the object from parse ParseRelation<ParseUser> mCustomerRelation = s

我在ParseObject中添加了一个与用户相关的关系,我想在listview中填充已添加到该关系的用户列表。这就是我目前所拥有的

protected List<ParseUser> mCustomers;
ParseObject shopinfo= new ParseObject("Shopinfo");
     // get the object from parse

ParseRelation<ParseUser> mCustomerRelation =   shopinfo.getRelation(ParseConstants.KEY_CUSTOMER_RELATION);
    mCustomerRelation.getQuery().findInBackground(new FindCallback<ParseUser>() {

        @Override
        public void done(List<ParseUser> customers, ParseException e) {
            if(e==null){
                mCustomers=customers;
                String[] people= new String [mCustomers.size()];
                int i=0;
                for(ParseUser customer : mCustomers){
                    people[i]=customer.getusername;
                    i++;
                }
                ArrayAdapter<String>adapter=new ArrayAdapter<String>(getListView().getContext(), 
                        android.R.layout.simple_list_item_1,people);
                setListAdapter(adapter);
            }
            else {
                AlertDialog.Builder builder = new AlertDialog.Builder(ResepActivity.this);
                builder.setMessage(e.getMessage())
                    .setTitle(R.string.error_title)
                    .setPositiveButton(android.R.string.ok, null);
                AlertDialog dialog = builder.create();
                dialog.show();

            }

        }
    });
受保护的mc客户列表;
ParseObject shopinfo=新的ParseObject(“shopinfo”);
//从解析中获取对象
ParseRelation MCCustomerRelation=shopinfo.getRelation(ParseConstants.KEY\u CUSTOMER\u关系);
mcCustomerRelation.getQuery().findInBackground(新的FindCallback()命令){
@凌驾
公共作废完成(列出客户,e){
如果(e==null){
mccustomers=客户;
String[]people=新字符串[mCustomers.size()];
int i=0;
用于(用户客户:MCcustomers){
people[i]=customer.getusername;
i++;
}
ArrayAdapteradapter=新的ArrayAdapter(getListView().getContext(),
android.R.layout.simple_list_item_1,people);
setListAdapter(适配器);
}
否则{
AlertDialog.Builder=新建AlertDialog.Builder(resecActivity.this);
builder.setMessage(例如getMessage())
.setTitle(R.string.error\u title)
.setPositiveButton(android.R.string.ok,null);
AlertDialog=builder.create();
dialog.show();
}
}
});

我在for循环中不断得到“java.lang.IllegalStateException:无法对与未保存的ParseObject的关联进行编码”

:getUsername是一个方法,其中有一个大写字母“U”。看起来您使用它不正确。尝试:

people[i] = customer.getUsername();
编辑: 我在评论中收到关于这个问题的更多信息后编辑了这个答案,然而,我的第一个答案仍然是对错误代码的修复

在发布相关问题之前,请通读解析文档。你要寻找的大多数答案都在文档中,它们非常好

由于您拥有所需ParseObject的对象ID,因此可以创建该对象,然后获取该对象的关系。而不是

ParseObject shopinfo= new ParseObject("Shopinfo");
使用以下命令:

ParseObject shopinfp = ParseObject.createWithoutData("Shopinfo", "objectID");

可以使用此方法从数据库中创建所需的parse对象,而无需使用ParseQuery。如果您拥有所需对象的objectID,并且希望在代码中使用该对象,请使用此方法。

不是这样……我尝试使用getUsername();但仍然会收到相同的错误消息..哪一行给出了该错误?如果您在“//从解析中获取对象”下发布了代码,也可能会有所帮助。很抱歉,我的意思是,当我将getusername更改为getusername时。当我运行应用程序时,它仍然会弹出“java.lang.IllegalStateException:无法编码与未保存的ParseObject的关联”…getusername只是一个输入错误..我将“//get the object from Parse”添加注释,让人们知道这就是我从Parse获取对象的方式(万一这是我出错的地方)哦,yikes,是的-那是错误的-我以为你那里有你没有写的代码。ParseObject shopinfo=newparseobject(“shopinfo”);正在创建一个新的空白Shopinfo对象。我认为您需要先从数据库中检索特定的ShopInfo对象,然后才能获取它的关系