Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes when the ViewPager is empty #22

Closed
fahimk opened this issue Jun 24, 2015 · 5 comments
Closed

Crashes when the ViewPager is empty #22

fahimk opened this issue Jun 24, 2015 · 5 comments

Comments

@fahimk
Copy link

fahimk commented Jun 24, 2015

 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setBackgroundResource(int)' on a null object reference
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
            at android.app.ActivityThread.-wrap11(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1343)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5401)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:725)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)
@subhanshuja
Copy link

@fahimk you forget to put color or drawable in your background resource

@fahimk
Copy link
Author

fahimk commented Jun 24, 2015

Here is the xml that I'm using, do I need to add an additional drawable?

                    <me.relex.circleindicator.CircleIndicator
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal|bottom"
                        android:layout_marginBottom="25dp"
                        app:ci_drawable="@drawable/ci_selected"
                        app:ci_drawable_unselected="@drawable/ci_unselected"
                        app:ci_height="7dp"
                        app:ci_width="7dp"/>

@subhanshuja
Copy link

@fahimk try use this one

<me.relex.circleindicator.CircleIndicator
            android:id="@+id/indicator"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|bottom"
            android:layout_marginBottom="25dp"
            app:ci_drawable="@drawable/circle_indicator"
            app:ci_drawable_unselected="@drawable/circle_indicator"
            app:ci_height="7dp"
            app:ci_width="7dp"/>

@orrc
Copy link

orrc commented Jun 26, 2015

This crash doesn't have anything to do with not overriding the drawables/colours.
Although View.setBackgroundResource() in the original stacktrace was enough info, here's a slightly more detailed stacktrace:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setBackgroundResource(int)' on a null object reference
  at me.relex.circleindicator.CircleIndicator.onPageSelected(CircleIndicator.java:153)
  at me.relex.circleindicator.CircleIndicator.setViewPager(CircleIndicator.java:129)
  at com.example.app.MainActivity.onCreate(MainActivity.java:51)
  at android.app.Activity.performCreate(Activity.java:6221)

The onPageSelected() method doesn't make any null checks.
If the ViewPager adapter is empty, no child views are added, so calling getChildAt(0) will return null:

152  View currentIndicator = getChildAt(mCurrentPosition);
153  currentIndicator.setBackgroundResource(mIndicatorUnselectedBackgroundResId);

@ongakuer
Copy link
Owner

Sorry. Busy working(T_T)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants