在MVP设计中将数据从Presenter传递到Fragment时,空指针异常

时间:2019-05-26 14:45:48

标签: java android android-fragments mvp android-mvp

我有一个视图作为项目中的主要活动,我已经创建了一个演示者和一个基于MVP的模型,现在我从视图中获得了一个字符串,并将其发送给演示者,演示者发送它到BioFragment,我也为片段创建了演示者和模型。实际上,主演示者将字符串传递给BioPresenterBioPresenter将其发送给BioFragment。问题出在这里,字符串毫无困难地转到了BioPresenter,但是它没有到​​达BioFragment,它在BioFragment中接收了函数,但是没有运行它。 / p>

MainActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_view);
    mainPresenter.attachView(this);
    mainPresenter.userArtistName("coldplay");

MainPresenter:

@Override
public void userArtistName(String artistName) {
    biographyPresenter.userArtistName(artistName);

BioFragPresenter:

   @Override
    public void userArtistName(String artistName) {
        bioFrag.userArtistName(artistName);

BiographyFragment:

@Override
public void userArtistName(String artistName) {

    bioFragPresenter.userArtistNameWithKey(artistName, GlobalConstants.theaudioDbApiKey);
}

Main Activity将数据传递给Main Presenter,Main Presenter将其传递给BioFrag Presenter,BioFrag将其传递给Biography片段。

错误:

 Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.music.artist.library.fragments.biography_mvp.BioFragContract$BioFragment.userArtistName(java.lang.String)' on a null object reference
    at com.music.artist.library.fragments.biography_mvp.BioFragPresenter.userArtistName(BioFragPresenter.java:36)
    at com.music.artist.library.main_core_mvp.MainPresenter.userArtistName(MainPresenter.java:26)
    at com.music.artist.library.main_core_mvp.MainViewActivity.onCreate(MainViewActivity.java:22)

0 个答案:

没有答案