lightSky / InfiniteIndicator

This lib can be used for viewpager infinite loop with indicator easily.
486 stars 102 forks source link

快速切换页签时报空指针 #8

Closed petma closed 9 years ago

petma commented 9 years ago

java.lang.NullPointerException at com.nineoldandroids.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:523) at com.nineoldandroids.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:410) at com.nineoldandroids.animation.ValueAnimator.startAnimation(ValueAnimator.java:1046) at com.nineoldandroids.animation.ValueAnimator.access$400(ValueAnimator.java:43) at com.nineoldandroids.animation.ValueAnimator$AnimationHandler.handleMessage(ValueAnimator.java:610) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method)

mAnimCircleIndicator.addSlider(defaultSliderView); 这一句抛出的异常

petma commented 9 years ago

1.我们项目最低版本是4.0,所以将nineoldandroids去掉了 2.将picasso去掉了,因为用这个框架,偶尔会展现不出图片。换成了你注释掉的另一个加载图片的方法。 3.AnimIndicator类中,createIndicators方法中,View view= getChildAt(mCurrentPage); 返回的对象有可能为空,这里可能会产生空针指异常,需要进行非空判断。

lightSky commented 9 years ago

非常感谢,我回头看下

lightSky commented 9 years ago

这个问题问题的原因是 mCurrentPage过大,导致getChildAt(mCurrentPage) 返回空,最终导致空指针 你可以使用这个方法getChildAt

private View getRealChildAt(int position) { return getChildAt(((RecyleAdapter) mViewPager.getAdapter()).getPosition(position)); }

会在下个版本中修复