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?
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
.