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

NullPointerException when adding values programmatically by setValues() #38

Open
devslava opened this issue Feb 11, 2016 · 8 comments
Open

Comments

@devslava
Copy link

In your example I added a button which sets values to HorizontalPicker by setValues() method.
When it is clicked, app crashes with NullPointerException

java.lang.NullPointerException at android.text.BoringLayout.getLineStart(BoringLayout.java:345) at android.text.Layout.getLineEnd(Layout.java:1130) at android.text.Layout.getLineExtent(Layout.java:955) at android.text.Layout.getLineWidth(Layout.java:942) at com.wefika.horizontalpicker.HorizontalPicker.onDraw(HorizontalPicker.java:281) at android.view.View.draw(View.java:14486) at android.view.View.getDisplayList(View.java:13383) at android.view.View.getDisplayList(View.java:13425) at android.view.View.draw(View.java:14203) at android.view.ViewGroup.drawChild(ViewGroup.java:3103) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940) at android.view.View.getDisplayList(View.java:13378) at android.view.View.getDisplayList(View.java:13425) at android.view.View.draw(View.java:14203) at android.view.ViewGroup.drawChild(ViewGroup.java:3103) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940) at android.view.View.getDisplayList(View.java:13378) at android.view.View.getDisplayList(View.java:13425) at android.view.View.draw(View.java:14203) at android.view.ViewGroup.drawChild(ViewGroup.java:3103) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940) at android.view.View.getDisplayList(View.java:13378) at android.view.View.getDisplayList(View.java:13425) at android.view.View.draw(View.java:14203) at android.view.ViewGroup.drawChild(ViewGroup.java:3103) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940) at android.view.View.draw(View.java:14489) at android.widget.FrameLayout.draw(FrameLayout.java:472) at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2327) at android.view.View.getDisplayList(View.java:13383) at android.view.View.getDisplayList(View.java:13425) at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1571) at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1450) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2409) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2281) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1892) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1005) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5750) 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:5017) 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:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)

If HorizontalPicker had GONE visibility, and by button click I add values and then make it visible, it crashes with another exception.

java.lang.IllegalArgumentException: Layout: -8 < 0 at android.text.Layout.<init>(Layout.java:138) at android.text.Layout.<init>(Layout.java:114) at android.text.BoringLayout.<init>(BoringLayout.java:145) at com.wefika.horizontalpicker.HorizontalPicker.setValues(HorizontalPicker.java:698) at com.wefika.horizontalpicker.example.MainActivity$1.onClick(MainActivity.java:53) at android.view.View.performClick(View.java:4443) at android.view.View$PerformClick.run(View.java:18443) 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:5017) 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:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)

devslava pushed a commit to devslava/HorizontalPicker that referenced this issue Feb 12, 2016
@devslava devslava mentioned this issue Feb 12, 2016
@ArcherN9
Copy link

Experiencing the same problem. I reckon this is on the snapshot release.

@devslava
Copy link
Author

@dakshsrivastava You can try my fork, I'm sure I've fixed this issue.
I've made pull request, but it is not approved yet;
#39

@ArcherN9
Copy link

@devslava Did just that. Took a checkout of your work. Got it working. Thanks a ton! 👍

@pratikdasa
Copy link

Hello, I have used gradle plugin to use this, all is working fine but when I am going to add it dynamically by using setValues its crashing and giving me error like Caused by: java.lang.IllegalArgumentException: Layout: -12 < 0, please help me out.

@AkbarBegimkulov
Copy link

AkbarBegimkulov commented Oct 10, 2016

I got library by compile 'com.wefika:horizontal-picker:1.1.1'. But I have this problem yet. How to get last version of Lib

@devslava
Copy link
Author

@pratikdasa @AkbarBegimqulov Try my fork. Download or clone and compile it. https://github.com/devslava/HorizontalPicker/tree/issues_37_38

@pratikdasa
Copy link

@devslava I have integrated updated library, error is solved, but now, when I am setting the sideItems value to 2 then its crashing with same error. Error line is in setValues method : layouts[i] = new BoringLayout(this.values[i], textPaint, itemWidth, Layout.Alignment.ALIGN_CENTER,
1f, 1f, boringMetrics, false, ellipsize, itemWidth);

Here itemWidth is creating problem. As before I have set static value 12 instead of itemWidth, it was working but now its crashing while sideItems value to 2. Please check and let me know.

@Kameswari
Copy link

@devslava
Thanks for pushing your fix. It saved my life :)

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

5 participants