{"action":"created","issue":{"url":"https://api.github.com/repos/ongakuer/CircleIndicator/issues/22","labels_url":"https://api.github.com/repos/ongakuer/CircleIndicator/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/ongakuer/CircleIndicator/issues/22/comments","events_url":"https://api.github.com/repos/ongakuer/CircleIndicator/issues/22/events","html_url":"https://github.com/ongakuer/CircleIndicator/issues/22","id":90558811,"number":22,"title":"Crashes when the ViewPager is empty","user":{"login":"fahimk","id":857824,"avatar_url":"https://avatars.githubusercontent.com/u/857824?v=3","gravatar_id":"","url":"https://api.github.com/users/fahimk","html_url":"https://github.com/fahimk","followers_url":"https://api.github.com/users/fahimk/followers","following_url":"https://api.github.com/users/fahimk/following{/other_user}","gists_url":"https://api.github.com/users/fahimk/gists{/gist_id}","starred_url":"https://api.github.com/users/fahimk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fahimk/subscriptions","organizations_url":"https://api.github.com/users/fahimk/orgs","repos_url":"https://api.github.com/users/fahimk/repos","events_url":"https://api.github.com/users/fahimk/events{/privacy}","received_events_url":"https://api.github.com/users/fahimk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-06-24T04:10:01Z","updated_at":"2015-06-26T16:25:41Z","closed_at":null,"body":"```java\r\n java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setBackgroundResource(int)' on a null object reference\r\n            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)\r\n            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)\r\n            at android.app.ActivityThread.-wrap11(ActivityThread.java)\r\n            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1343)\r\n            at android.os.Handler.dispatchMessage(Handler.java:102)\r\n            at android.os.Looper.loop(Looper.java:148)\r\n            at android.app.ActivityThread.main(ActivityThread.java:5401)\r\n            at java.lang.reflect.Method.invoke(Native Method)\r\n            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:725)\r\n            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)\r\n```"},"comment":{"url":"https://api.github.com/repos/ongakuer/CircleIndicator/issues/comments/115746283","html_url":"https://github.com/ongakuer/CircleIndicator/issues/22#issuecomment-115746283","issue_url":"https://api.github.com/repos/ongakuer/CircleIndicator/issues/22","id":115746283,"user":{"login":"orrc","id":138615,"avatar_url":"https://avatars.githubusercontent.com/u/138615?v=3","gravatar_id":"","url":"https://api.github.com/users/orrc","html_url":"https://github.com/orrc","followers_url":"https://api.github.com/users/orrc/followers","following_url":"https://api.github.com/users/orrc/following{/other_user}","gists_url":"https://api.github.com/users/orrc/gists{/gist_id}","starred_url":"https://api.github.com/users/orrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orrc/subscriptions","organizations_url":"https://api.github.com/users/orrc/orgs","repos_url":"https://api.github.com/users/orrc/repos","events_url":"https://api.github.com/users/orrc/events{/privacy}","received_events_url":"https://api.github.com/users/orrc/received_events","type":"User","site_admin":false},"created_at":"2015-06-26T16:25:41Z","updated_at":"2015-06-26T16:25:41Z","body":"This crash doesn't have anything to do with not overriding the drawables/colours.\r\nAlthough `View.setBackgroundResource()` in the original stacktrace was enough info, here's a slightly more detailed stacktrace:\r\n\r\n```\r\nCaused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setBackgroundResource(int)' on a null object reference\r\n  at me.relex.circleindicator.CircleIndicator.onPageSelected(CircleIndicator.java:153)\r\n  at me.relex.circleindicator.CircleIndicator.setViewPager(CircleIndicator.java:129)\r\n  at com.example.app.MainActivity.onCreate(MainActivity.java:51)\r\n  at android.app.Activity.performCreate(Activity.java:6221)\r\n```\r\n\r\nThe `onPageSelected()` method doesn't make any `null` checks.\r\nIf the `ViewPager` adapter is empty, [no child views are added](https://github.com/ongakuer/CircleIndicator/blob/e25c9dd/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java#L170-L173), so calling `getChildAt(0)` will return `null`:\r\n```\r\n152  View currentIndicator = getChildAt(mCurrentPosition);\r\n153  currentIndicator.setBackgroundResource(mIndicatorUnselectedBackgroundResId);\r\n```"}}