我有一个视图作为项目中的主要活动,我已经创建了一个演示者和一个基于MVP的模型,现在我从视图中获得了一个字符串,并将其发送给演示者,演示者发送它到BioFragment
,我也为片段创建了演示者和模型。实际上,主演示者将字符串传递给BioPresenter
,BioPresenter
将其发送给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)