java - EventBus 3.0 nullPoint異常?
問題描述
異常信息如下
java.lang.NullPointerException: Attempt to invoke virtual method ’java.lang.Class java.lang.Object.getClass()’ on a null object reference at org.greenrobot.eventbus.EventBus.postSingleEvent(EventBus.java:363) at org.greenrobot.eventbus.EventBus.post(EventBus.java:251) at com.culsomusic2.coreclass.BasePlayActivity.playBaseMusic(BasePlayActivity.java:90)at com.culsomusic2.songlistmodule.ui.mactivity.activityEntity.SongContentActivity$4.onItemClick(SongContentActivity.java:252) at com.zhy.adapter.recyclerview.MultiItemTypeAdapter$1.onClick(MultiItemTypeAdapter.java:68)at android.view.View.performClick(View.java:5198)at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
EventBus 注冊(cè)和反注冊(cè)如下 @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = MyApplication.getContext(); Intent intent = new Intent(mContext, BaseControlService.class); startService(intent); //注冊(cè)EventBus EventBus.getDefault().register(this);}
@Override
protected void onDestroy() { //反注冊(cè)EventBus EventBus.getDefault().unregister(this); mContext = null; super.onDestroy();}
調(diào)用的方法如下 public void playBaseMusic(@Nullable BaseTagBean bean) {
BaseTagBean tagBean; if (bean==null){tagBean=new BaseTagBean();tagBean.setTag(CONTROL_TAG_PLAY); }else {tagBean=bean;tagBean.setTag(CONTROL_TAG_PLAY); } EventBus.getDefault().post(tagBean);}
只要調(diào)用上述playBaseMusic方法它就在EventBus.getDefault().post(tagBean);這個(gè)地方報(bào)空指針錯(cuò)誤;請(qǐng)問大家如何解決。
問題解答
回答1:目前這種情況看,只有可能是你的tagbean是null了,打個(gè)斷點(diǎn)看看吧。
相關(guān)文章:
1. macos - 無法source activate python272. javascript - 微信網(wǎng)頁開發(fā)從菜單進(jìn)入頁面后,按返回鍵沒有關(guān)閉瀏覽器而是刷新當(dāng)前頁面,求解決?3. 預(yù)訂金和尾款分別支付4. javascript - h5微信中怎么禁止橫屏5. empty比isset更嚴(yán)格一點(diǎn)6. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?7. 我在導(dǎo)入模板資源時(shí)遇到無法顯示的問題,請(qǐng)老師解答下8. PHPExcel表格導(dǎo)入數(shù)據(jù)庫怎么導(dǎo)入9. thinkphp6使用驗(yàn)證器 信息如何輸出到前端頁面10. python - sqlalchemy更新數(shù)據(jù)報(bào)錯(cuò)

網(wǎng)公網(wǎng)安備