适用于Android的RxJava:InvocationTargetException

时间:2016-01-13 12:56:48

标签: android retrofit mvp rx-java invocationtargetexception

我想使用MVP模式使用RxJava和Retrofit测试一些方法。我通过Presenter调用API,并使用subscribeOn方法InvocationTargetException使用nullPointer调用API。为什么我得到那个例外?

mSubscription = mIEmailModel.validateEmail(emailObject)
            .subscribeOn(Schedulers.newThread())
            .subscribe(new Subscriber<Response<ServerResponse>>() {
                @Override
                public void onCompleted() {
                    mIValidEmViewPresenter.hideProgressDialog();
                }

                @Override
                public void onError(Throwable e) {
                    mIValidEmViewPresenter.hideProgressDialog();
                    mIValidEmViewPresenter.onEmailValidationError();
                }

                @Override
                public void onNext(Response<ServerResponse> serverResponse) {
                    if (serverResponse.code() == 200) {
                        mIValidEmViewPresenter.onEmailValidationSuccess();
                    } else {
                        mIValidEmViewPresenter.onEmailValidationFailed();
                    }
                }
            });

这是logcat:

java.lang.NullPointerException
at studio3s.com.rxmvphelloworld.Cata.Presenter.EmailPresenter.validateEmail(EmailPresenter.java:34)
at studio3s.com.rxmvphelloworld.Cata.Presenter.EmailPresenterTest.testValidateEmail(EmailPresenterTest.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

0 个答案:

没有答案