jeasonlzy / HeaderViewPager

具有共同头部的 ViewPager,支持与ListView,GridView,ScrollView,WebView,RecyclerView 嵌套使用。具有连续的滑动事件 和 滑动监听, 支持下拉刷新。
769 stars 178 forks source link

空指针异常 #5

Open maoxiandemeng opened 8 years ago

maoxiandemeng commented 8 years ago

You should call ScrollableHelper.setCurrentScrollableContainer() to set ScrollableContainer. 按照你说的写的 我设置了这个属性,还报这个错误

jeasonlzy commented 8 years ago

具体的异常信息。。哪行代码。。

maoxiandemeng commented 8 years ago

继承你写的那个Fragment重写一个方法,得到的view一直是空,不知道啥情况,愣是没看出来

xiaqiuming commented 8 years ago

java.lang.NullPointerException: You should call ScrollableHelper.setCurrentScrollableContainer() to set ScrollableContainer. at com.lzy.widget.HeaderScrollHelper.isTop(HeaderScrollHelper.java:55) at com.lzy.widget.HeaderViewPager.computeScroll(HeaderViewPager.java:227) at android.view.View.updateDisplayListIfDirty(View.java:14174) at android.view.View.getDisplayList(View.java:14209) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3390) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3369) at android.view.View.updateDisplayListIfDirty(View.java:14147) at android.view.View.getDisplayList(View.java:14209) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3390) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3369) at android.view.View.updateDisplayListIfDirty(View.java:14147) at android.view.View.getDisplayList(View.java:14209) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3390) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3369) 应该和我的异常时一样,就是demo报的这个错,偶现

xiaqiuming commented 8 years ago

@jeasonlzy0216

maxlzw12 commented 8 years ago

@xiaqiuming 同这位兄弟一模一样的问题,偶发性~

xiaqiuming commented 8 years ago

这个问题是因为activity回收了之后,fragment重建了。 if (savedInstanceState != null) { HomeFragment = (NewsFragment) getSupportFragmentManager().findFragmentByTag(MyFragmentPagerAdapter.makeFragmentName(viewPager.getId(), 0)); } else { HomeFragment = new NewsFragment(); } 这里的MyFragmentPagerAdapter是拷贝的PagerAdapter的源码,只是为了把makeFragmentName(),这个方法变为public的 这样做避免重复的建framgment,也可以重写onSaveInstanceState,不保存状态,就不用去找fragment了 @Override protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); } @maxlzw12 @maoxiandemeng

user-xuhan commented 7 years ago

这个问题解决了吗,我也是这个问题。更新tabs和fragments就会出现这个问题

heyangJob commented 7 years ago

fragment里面嵌套fragment 外面的fragment销毁了,里面的也随之销毁,这个时候滑动,就会报空指针异常,接口类里面只只能了getView ,应该加一个setView