0

I installed Moxy to my project, and set annotations according to docs. But, when i launch the app, it crashes with:

FATAL EXCEPTION: main
                                                                      Process: com.example.project, PID: 709
                                                                      java.lang.NullPointerException
                                                                          at com.example.project.presentation.presenter.splash.SplashPresenter.checkLoggedInAndNavigate(SplashPresenter.java:35)

Dependencies in build.gradle:

    ...
    // Moxy
    compile 'com.arello-mobile:moxy:1.3.3'
    provided 'com.arello-mobile:moxy-compiler:1.3.3'
    compile 'com.arello-mobile:moxy-app-compat:1.3.3'
}

Here is View interface:

    public interface SplashView extends MvpView {

    void navigateToMainScreen();

    void navigateToLoginScreen();
}

Here is activity, what implements that view:

     public class SplashActivity extends MvpAppCompatActivity implements SplashView {

        public static final String TAG = "SplashActivity";

        @InjectPresenter
        SplashPresenter mSplashPresenter;
        ...
}

This is the code, where it crashes:

@InjectViewState
public class SplashPresenter extends MvpPresenter<SplashView> {

    SplashModel mModel = new SplashModel();

    ...

    public void checkLoggedInAndNavigate() {

        if (checkLoggedIn()) {
            getViewState().navigateToMainScreen();
        } else {
            getViewState().navigateToLoginScreen();
        }
    }
}

When it tries to get ViewState (Which autogenerated by annotation), it throws an exception

What's wrong with that?

Arash GM
  • 10,316
  • 6
  • 58
  • 76
Koroqe
  • 67
  • 7
  • Hi, you can try to replace `provided 'com.arello-mobile:moxy-compiler:1.3.3'` to `annotationProcessor 'com.arello-mobile:moxy-compiler:1.3.3'`. Also, I recommend use the last version of Moxy ( now it's 1.4.5) and disable jack. – senneco Feb 14 '17 at 00:14
  • Hello! That I open same issue on GitHub :). Thanks for the help! Add an answer, please, so that I can select it as the best. – Koroqe Feb 15 '17 at 07:34
  • Extract it as answer =) – senneco Feb 15 '17 at 07:54

1 Answers1

2

You can try to replace provided 'com.arello-mobile:moxy-compiler:1.3.3' to annotationProcessor 'com.arello-mobile:moxy-compiler:1.3.3'. Also, I recommend use the last version of Moxy (now it's 1.4.5) and disable jack.

senneco
  • 1,786
  • 2
  • 12
  • 15