Search code examples
javaandroidmosby

Mosby Framework - getView cause ClassCastException


I just create a simple/blank fragment, which should use the MosbyFramework. Every time I'm using the getView()method I'm getting the error:

java.lang.ClassCastException: de.xxx.projectZ.packA.AFragment cannot be cast to de.xxx.projectZ.packA.AView

public interface AView extends MvpLceView<List<Persons>> {
  // empty
}

My presenter which cause the error

public class APresenter extends MvpBasePresenter<AView> {
    PersonsRepository personsRepository;

    @Inject
    public APresenter(PersonsRepositoryImpl personsRepository) {
        this.personsRepository = personsRepository;
    }

    public void loadPersons() {
// ERROR
        if (isViewAttached())
            getView().showLoading(true);

        List<Person> persons = personsRepository.getPersons();


        if (isViewAttached()) {

        }
    }
}

My fragment header

public class PersonsFragment
        extends MvpLceFragment<SwipeRefreshLayout, List<Person>, AView, APresenter> {

Does anybody know why this happen?


Solution

  • your Fragment is not implementing AView ...

    public class PersonsFragment
            extends MvpLceFragment<SwipeRefreshLayout, List<Person>, AView, APresenter> 
    
            implements AView  // This is missing
    {
     ...
    }