shichaohui / PageRecyelerViewDemo

横向分页的RecyclerView,带有页码指示器。
http://blog.csdn.net/u014165119/article/details/46834265
284 stars 68 forks source link

Invalid item position 0(0). Item count:0 com.yf.huijulauncher.recycleview.PageRecyclerView{4204f710 VFED.... ......I. 0,0-0,0 #7f09003f app:id/app_list_rv}, adapter:com.yf.huijulauncher.recycleview.PageRecyclerView$PageAdapter@41d58a10, layout:com.yf.huijulauncher.recycleview.AutoGridLayoutManager@421462f8, context:com.yf.huijulauncher.activity.AppListActivity@42042bd0 at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5616) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5589) #3

Open Aima09 opened 6 years ago

Aima09 commented 6 years ago

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.yf.huijulauncher, PID: 602 java.lang.IndexOutOfBoundsException: Invalid item position 0(0). Item count:0 com.yf.huijulauncher.recycleview.PageRecyclerView{4204f710 VFED.... ......I. 0,0-0,0 #7f09003f app:id/app_list_rv}, adapter:com.yf.huijulauncher.recycleview.PageRecyclerView$PageAdapter@41d58a10, layout:com.yf.huijulauncher.recycleview.AutoGridLayoutManager@421462f8, context:com.yf.huijulauncher.activity.AppListActivity@42042bd0 at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5616) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5589) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5585) at com.yf.huijulauncher.recycleview.AutoGridLayoutManager.onMeasure(AutoGridLayoutManager.java:48) at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3124) at com.yf.huijulauncher.recycleview.PageRecyclerView.onMeasure(PageRecyclerView.java:106) at android.view.View.measure(View.java:16518) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052) at android.widget.LinearLayout.onMeasure(LinearLayout.java:590) at android.view.View.measure(View.java:16518) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) at android.view.View.measure(View.java:16518) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139) at android.view.View.measure(View.java:16518) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) at android.view.View.measure(View.java:16518) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at android.view.View.measure(View.java:16518) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) at android.view.View.measure(View.java:16518) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2410) at android.view.View.measure(View.java:16518) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1921) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1114) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1296) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1001) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5680) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java:574) at android.view.Choreographer.doFrame(Choreographer.java:544) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invoke

报了一个这样的错误 在下面代码引起的,怎么解决? @Override public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) { if (measuredHeight <= 0) { View view = recycler.getViewForPosition(0); if (view != null) { measureChild(view, widthSpec, heightSpec); measuredWidth = View.MeasureSpec.getSize(widthSpec); measuredHeight = view.getMeasuredHeight() * getSpanCount(); } } setMeasuredDimension(measuredWidth, measuredHeight); }

ilkeew commented 6 years ago

我也是报了Invalid item position 0(0) 如何解决?

syusikoku commented 5 years ago

@Override public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) { if (measuredHeight <= 0 && state.getItemCount() > 0) { // View view = recycler.getViewForPosition(0); View view = recycler.getViewForPosition(0); if (view != null) { measureChild(view, widthSpec, heightSpec); measuredWidth = View.MeasureSpec.getSize(widthSpec); measuredHeight = view.getMeasuredHeight() * getSpanCount(); } } setMeasuredDimension(measuredWidth, measuredHeight); } 这种方式解决问题

wangchao789789 commented 5 years ago

不报错了 但是显示不了东西,只有分页的指示器