(MVP) Moxy 的 getViewState() 中的 NullPointerException
NullPointerException in (MVP) Moxy's getViewState()
我在我的项目中安装了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'
}
查看界面如下:
public interface SplashView extends MvpView {
void navigateToMainScreen();
void navigateToLoginScreen();
}
这里是 activity,是什么实现了那个视图:
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(由注释自动生成)时,它会抛出异常
这有什么问题?
您可以尝试将provided 'com.arello-mobile:moxy-compiler:1.3.3'
替换为annotationProcessor 'com.arello-mobile:moxy-compiler:1.3.3'
。此外,我建议使用最新版本的 Moxy(现在是 1.4.5)并禁用 jack
.
我在我的项目中安装了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'
}
查看界面如下:
public interface SplashView extends MvpView {
void navigateToMainScreen();
void navigateToLoginScreen();
}
这里是 activity,是什么实现了那个视图:
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(由注释自动生成)时,它会抛出异常
这有什么问题?
您可以尝试将provided 'com.arello-mobile:moxy-compiler:1.3.3'
替换为annotationProcessor 'com.arello-mobile:moxy-compiler:1.3.3'
。此外,我建议使用最新版本的 Moxy(现在是 1.4.5)并禁用 jack
.