我在项目中安装了Moxy,并根据文档设置了注释。但是,当我启动应用程序时,它崩溃了:
FATAL EXCEPTION: main
Process: com.example.project, PID: 709
java.lang.NullPointerException
at com.example.project.presentation.presenter.splash.SplashPresenter.checkLoggedInAndNavigate(SplashPresenter.java:35)
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'
}
这是View界面:
public interface SplashView extends MvpView {
void navigateToMainScreen();
void navigateToLoginScreen();
}
这是活动,实现该视图的内容:
public class SplashActivity extends MvpAppCompatActivity implements SplashView {
public static final String TAG = "SplashActivity";
@InjectPresenter
SplashPresenter mSplashPresenter;
...
}
这是崩溃的代码:
@InjectViewState
public class SplashPresenter extends MvpPresenter<SplashView> {
SplashModel mModel = new SplashModel();
...
public void checkLoggedInAndNavigate() {
if (checkLoggedIn()) {
getViewState().navigateToMainScreen();
} else {
getViewState().navigateToLoginScreen();
}
}
}
当它试图获取ViewState(由注释自动生成)时,它会抛出异常
这有什么问题?
答案 0 :(得分:2)
您可以尝试将provided 'com.arello-mobile:moxy-compiler:1.3.3'
替换为annotationProcessor 'com.arello-mobile:moxy-compiler:1.3.3'
。另外,我建议使用最新版本的Moxy(现在是1.4.5)并禁用jack
。