タブ レイアウトのビュー ページャーを使用しています。3 番目のタブでは、Recyclerview を保持するフラグメントを使用しています。タブをスワイプして 3 番目のタブに到達すると、エラーが表示されます。
Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView$LayoutManager.stopSmoothScroller()' on a null object reference
何が問題なのかわかりません。データはサーバーからフェッチされていますが、アプリがクラッシュしています。問題に関連するGoogleで多くの検索を行いましたが、有効な回答が得られませんでした。
これは、そのフラグメントの recylerview 実装のコードです。
recyclerView = (RecyclerView) layout.findViewById(R.id.staggeredGridDesign);
adapter = new AdapterDesigns(getActivity());
manager = new GridLayoutManager(getActivity(), 2, LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(manager);
recyclerView.swapAdapter(adapter, false);
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (m == 1 && listMen.size() % 2 != 0) {
if (position == 0)
return 2;
} else if (w == 1 && listWomen.size() % 2 != 0) {
if (position == 0)
return 2;
}
return 1;
}
});
adapter.setDesignList(listMen);
LogCat :
Process: stvisionary.fashionove.com, PID: 31886
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView$LayoutManager.stopSmoothScroller()' on a null object reference
at android.support.v7.widget.RecyclerView.stopScrollersInternal(RecyclerView.java:1229)
at android.support.v7.widget.RecyclerView.stopScroll(RecyclerView.java:1221)
at android.support.v7.widget.RecyclerView.onDetachedFromWindow(RecyclerView.java:1426)
at android.view.View.dispatchDetachedFromWindow(View.java:13459)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2839)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2836)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2836)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2836)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2836)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2836)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4165)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4138)
at android.view.ViewGroup.removeView(ViewGroup.java:4070)
at android.support.v4.view.ViewPager.removeView(ViewPager.java:1326)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1055)
at android.support.v4.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1233)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:709)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:488)
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:249)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:549)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
08-