0

I have added a relation in an ParseObject which relate to Users, and I would like populate the list of Users who have been added to the relation on an listview. this is what i have so far.

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();

            }

        }
    });

I kept getting "java.lang.IllegalStateException:unable to encode an association with an unsaved ParseObject"

1 Answer 1

1

Inside your for-loop: getUsername is a method, and there's a capital 'U'. It appears you are using it incorrectly. try:

people[i] = customer.getUsername();

EDIT: I'm editing this answer after receiving more information about the problem in the comments, however, my first answer is still a fix to erroneous code.

Please read all the way through the parse docs before posting questions about it. Most of the answers you are looking for are right in the docs, they are very good.

Since you have the object ID for the ParseObject you want, you can create the object, then get the relation for it. Instead of

ParseObject shopinfo= new ParseObject("Shopinfo");

use this:

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

You can use this method to create the parse object from your database that you want without using a ParseQuery. Use this method if you have the objectID of the object you want, and you want to work with the object in your code.

Sign up to request clarification or add additional context in comments.

9 Comments

thats not it...i tried to use getUsername(); but still get the same error message..
which exact line is giving you that error? it might also help if you posted the code you have under "//get the object from Parse"
sorry about the mistake, but what i meant is that when i change getusername to getUsername. when i run the app it still pops out "java.lang.IllegalStateException:unable to encode an association with an unsaved ParseObject"...the getusername is just an typo..
I put "//get the object from Parse" to add the comment to let people know that this is how i get the object from parse( incase this is where i got wrong)
oh, yikes, yes - that is wrong - I thought you had code there that you just didn't write. all you have done with the line ParseObject shopinfo= new ParseObject("Shopinfo"); is create a new, blank, Shopinfo object. I think you want to retrieve a particular ShopInfo object from your database before you can get a relation for it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.