Android开发之SwipeMenuRecyclerView$2@f5b62e8 was not registered.


11-11 18:33:29.752 23307-23307/com.vincent.cloud E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   Process: com.vincent.cloud, PID: 23307
                                                                   java.lang.IllegalStateException: Observer com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView$2@f5b62e8 was not registered.
                                                                       at android.database.Observable.unregisterObserver(Observable.java:69)
                                                                       at android.support.v7.widget.RecyclerView$Adapter.unregisterAdapterDataObserver(RecyclerView.java:6583)
                                                                       at com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView.setAdapter(SwipeMenuRecyclerView.java:301)
                                                                       at com.vincent.cloud.ui.fragment.CommonProblemFragment.initRecycleView(CommonProblemFragment.java:134)
                                                                       at com.vincent.cloud.ui.fragment.CommonProblemFragment.onCreateView(CommonProblemFragment.java:125)
                                                                       at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                       at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                       at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:753)
                                                                       at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                       at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                       at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                       at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984)
                                                                       at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
                                                                       at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
                                                                       at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                       at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:668)
                                                                       at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:630)
                                                                       at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:611)
                                                                       at com.vincent.cloud.ui.CommonProblemActivity.onViewClicked(CommonProblemActivity.java:169)
                                                                       at com.vincent.cloud.ui.CommonProblemActivity_ViewBinding$2.doClick(CommonProblemActivity_ViewBinding.java:57)
                                                                       at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
                                                                       at android.view.View.performClick(View.java:5646)
                                                                       at android.view.View$PerformClick.run(View.java:22459)
                                                                       at android.os.Handler.handleCallback(Handler.java:761)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                       at android.os.Looper.loop(Looper.java:156)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6523)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)

如上,提示RecycelVeiw没有注册,报错行代码只是设置了一个adapter
需要重新注册一下adapter
解决方法:


 adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
            @Override
            public void onChanged() {
                super.onChanged();
                if(recyclerView!=null&&recyclerView.getAdapter() == null){
                    recyclerView.setAdapter(adapter);
                }
            }
        });

———————————————2017年11月11日18:38:43————————————————-

你可能感兴趣的:(android,开发,综合)