Search code examples
androidparse-platformunchecked

How to fix "Unchecked call to findInBackground" with Parse.com API


I'm going through an Android app I've ported from iOS and trying to figure out the causes of any warnings I'm getting and get my code in line with Android Studio's lint.

So far, most of the "problems" have been pretty easy fixes, but I've got a warning with a particular Parse.com API function that has me stumped.

Here's the code:

private void loadData() {
    ParseQuery query = ParseQuery.getQuery("someClass");
    query.include("someProperty1");
    query.include("someProperty2");
    query.include("someProperty3");
    query.orderByAscending("sequence");
    query.whereEqualTo("owner", ParseUser.getCurrentUser());

    // This next line causes the warning
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> items, ParseException e) {
            if (e != null) {
                // Error handling here

            } else {
                // Got query results here

            }
        }
    });
}

The warning that is showing up is:

Unchecked call to 'findInBackground(FindCallback < T >)' as a member of raw type 'com.parse.ParseQuery'.

When you allow autocomplete to "fill out" a new FindCallback for you, you get this:

query.findInBackground(new FindCallback() {
    @Override
    public void done(List list, ParseException e) {

    }

    @Override
    public void done(Object o, Throwable throwable) {

    }
});

Well, that's annoying, because the actual results that are returned are a List of type ParseObject. So, I edited that code to my code above in order to streamline my code. The interesting thing is that even the autocomplete code has the same warning associated with it.

I think I understand to reason that this warning is generated, but I've attempted as best I can to specify my types. Is there something more I can do to make my code work? Or rather, given that I can't re-write Parse's code, how do I correctly fix this warning?


Solution

  • You just need to type your ParseQuery:

    Replace ParseQuery query with ParseQuery<ParseObject> query