Backendless Support
 
Solved

java.util.HashMap cannot be cast to EpilepsyGroupUser

This is a backendless generated class. I call the service to retrieve the data which returns an Arraylist<EpilepsyGroupUser>

When i try to use retrieve the data in this list it crashes with a class cast exception

Leave a Comment

Comments (20)

photo
1

Could you please provide a snippet of the code showing how you're retrieving the data and where the class cast happens?

photo
1

  1. mService.getSupportGroupAsync(mUser.getUserId(), 0, new AsyncCallback<ArrayList<EpilepsyGroupUser>>() {

    @Override

    public void handleResponse(ArrayList<EpilepsyGroupUser> response) {

    mMyCircleList = response;

    setUpMyCircle();

    }

    @Override

    public void handleFault(BackendlessFault fault) {

    }

    });

  1. public void onBindViewHolder(ViewHolder holder, int position) {

    String name = mData.get(position).getFirstName() + " " + mData.get(position).getLastName();

    String imageUrl = mData.get(position).getProfilePicUrl();

    holder.name.setText(name);

    holder.image.setImageResource( default_profile);

    if(imageUrl != null) {

    new DownloadImageTask().setImage(imageUrl, holder.image);

    }

    }

photo
1

What does "mService.getSupportGroupAsync" do? Does it call a custom API service?

Basically I need to understand how the data is fetched from the server. Unfortunately, the example you provided does not provide any insight for that.

photo
1

  1. public void getSupportGroupAsync(String encParentUserId, int offset, AsyncCallback<ArrayList<EpilepsyGroupUser>> callback)

    {

    Object[] args = new Object[]{encParentUserId, offset};

    Backendless.CustomService.invoke( SERVICE_NAME, SERVICE_VERSION_NAME, "getSupportGroup", args, ArrayList.class, callback);

    }

photo
1

Thanks, this helps. One more question, does the service retrieve "EpilepsyGroupUser" objects from the database?

photo
1

Yes

photo
1

Then add the following line of code before you call the service:

Backendless.Data.MapTableToClass( "EpilepsyGroupUser", EpilepsyGroupUser.class )

photo
1

I have still get the same error

  1. public View onCreateView(LayoutInflater inflater, ViewGroup container,

    Bundle savedInstanceState) {

    // Inflate the layout for this fragment

    Backendless.Data.mapTableToClass( "EpilepsyGroupUser", EpilepsyGroupUser.class );

    mService = EpilepsyService.getInstance();

    View v = inflater.inflate(R.layout.fragment_circle, container, false);

    ButterKnife.bind(this, v);

    Bundle b = getArguments();

    if (b != null && !b.isEmpty()) {

    User mUser = b.getParcelable(USER_EXTRA);

    mService.getSupportGroupAsync(mUser.getUserId(), 0, new AsyncCallback<ArrayList<EpilepsyGroupUser>>() {

    @Override

    public void handleResponse(ArrayList<EpilepsyGroupUser> response) {

    mMyCircleList = response;

    setUpMyCircle();

    }

    @Override

    public void handleFault(BackendlessFault fault) {

    }

    });

    }

    return v;

    }

photo
1

What is your app ID?

photo
1

CE6DAFE1-FEAB-9A8E-FFA9-BA98F212A300

photo
1

Thanks. We will take a look a bit later today

photo
1

What "mUser.getUserId()" can I use to invoke the service in order to see a response?

photo
1

I'm not sure what you mean because the way you are asking the question but i think you mean how can you use the service.

Heres a user id 9C0516B6-1047-7D11-FFBD-66F7518EAD00.

and you can use the getPatientByUserId to get a response

  1. public EpilepsyPatient getPatientByUserId(String userId)

    {

    Object[] args = new Object[]{userId};

    return Backendless.CustomService.invoke( SERVICE_NAME, SERVICE_VERSION_NAME, "getPatientByUserId", args, EpilepsyPatient.class );

    }

photo
1

What I wanted to ask is what arguments can I pass into the service call to get s response which has epilepsypatient objects.

photo
1

A user id is the simplest thing you can use

photo
1

When I invoke "getSupportGroup" with "9C0516B6-1047-7D11-FFBD-66F7518EAD00" and "0" for the offset, I get an empty array back. Please help me with the arguments so I can get the actual response:

7ecb4167c2291b489dea91980170c3eb

photo
1

kZAHxpjlLOdT3vUTzTnN1i17NVUJryZ3H/BaBsrTGsFhdKrq3I7Og2xEotHfyeoB

photo
1

try that

photo
1

Thanks, it helped.

Here's what mapTableToClass should look like:

  1. Backendless.Data.MapTableToClass( "epilepsy.EpilepsyGroupUser", EpilepsyGroupUser.class )

photo
1

That worked thank you