void android.support.v4.app.Fragment.setMenuVisibility(boolean)' on a null object reference
oh yes.. i finally found my mistake.. first of all there is no mistake in my code. everything is right.
i have three tab layout and i m passing only for one tablayout and other two are getting null, so i must have to apply three switch case statement.
public Fragment getItem(int position) {
Fragment fragment = null;
switch(position){
case product_result:
fragment = FragmentProduct.newInstance("","");
break;
}
return fragment;
}
instead
public Fragment getItem(int num) {
Fragment fragment = null;
switch (num) {
case TAB_PRODUCT_RESULT:
fragment = FragmentProduct.newInstance("", "");
break;
case TAB_SECOND:
fragment = MyFragment.getInstance(num);
break;
case TAB_THIRD:
fragment = MyFragment.getInstance(num);
break;
}
return fragment;
}
thats it..
I think the problem is in the public Fragment getItem(int position)
method of your MyPagerAdapter
. Your code snippet below is returning null
fragments.
Fragment fragment = null;
switch(position){
case product_result:
fragment = FragmentProduct.newInstance("","");
break;
}
return fragment;
You only get a real fragment for the position 0
, because product_result
is initialized to 0
. In all other cases it returns null. Modify the above snippet of code to always return a fragment instance that is not null.