Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restartLoader issue #1

Open
Shivadumnawar opened this issue Jan 27, 2022 · 1 comment
Open

restartLoader issue #1

Shivadumnawar opened this issue Jan 27, 2022 · 1 comment
Labels

Comments

@Shivadumnawar
Copy link

Hello mam, I followed your code, it is very interesting and understanding. In MainActivity.java,
loaderManager.restartLoader(BOOK_LOADER_ID, bundle, this);
In the above code, for callback : this
It is showing error
Required type:
LoaderCallbacks

Provided:
MainActivity

reason: no instance(s) of type variable(s) D exist so that MainActivity conforms to LoaderCallbacks

This one line code is stopping me from execution of entire app.
Please feel free to respond. This is my favourite app as a beginner. Thank you.

@judit-juhasz
Copy link
Owner

Hi @Shivadumnawar , Thank you for being interested in my app. :)

I have not used this application since I finished it, and I am not following closely the Android development, however this is what I think:

The restartLoader's expects aLoaderCallbacks object as its third argument. The this object is a MainActivity class, but that class also implements LoaderManager.LoaderCallbacks<D> (precisely LoaderManager.LoaderCallbacks<List<Book>>, but the List<Book> does not matter now), so it should be correct, right? I quickly checked the documention, and this is what I found:

This interface was deprecated in API level 28.
Use the Support Library LoaderManager.LoaderCallbacks

It could be that you are using a newer version of the API and the restartLoader method actually expects a android.support.v4.app.LoaderManager.LoaderCallbacks<D> class. Do not be confused by the class name, if they are in a different namespace (e.g. android.app.LoaderManager vs android.support.v4.app.LoaderManager) they are different classes for the compiler. That can be the reason why you did not understand why the error message complains about the LoaderCallbacks while the this implements a LoaderCallbacks (it is, but another one).

It seems that the old LoaderCallbacks and the LoaderCallbacks have similar methods, so it can be enough that you just replace the namespace in line 23 (plus adjust the imports, etc.).

This is just a guess because, unfortunately, I do not have an Android development environment so I cannot test my theory. I hope it helps, and good luck learning! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants