-
Notifications
You must be signed in to change notification settings - Fork 55
Description
This is my piece of code for adding items to the lucky wheel :
val b = ArrayList<WheelItem>() val bitmap = BitmapFactory.decodeResource(resources, R.drawable.circle) b.add((WheelItem(Color.parseColor("#FFFFFF"), bitmap, "Test"))) b.add((WheelItem(Color.parseColor("#FFFFFF"), bitmap, "Test"))) luckyWheel.addWheelItems(b)
This is the error I'm getting :
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at com.bluehomestudio.luckywheel.WheelView.drawImage(WheelView.java:133)
at com.bluehomestudio.luckywheel.WheelView.onDraw(WheelView.java:245)
at android.view.View.draw(View.java:23194)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at android.widget.ScrollView.draw(ScrollView.java:1869)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at androidx.recyclerview.widget.RecyclerView.drawChild(RecyclerView.java:5030)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at androidx.recyclerview.widget.RecyclerView.draw(RecyclerView.java:4429)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1994)
at android.view.View.draw(View.java:23197)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
E/AndroidRuntime: at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.View.draw(View.java:22925)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23197)
at com.android.internal.policy.DecorView.draw(DecorView.java:821)
at android.view.View.updateDisplayListIfDirty(View.java:22061)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:689)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:695)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:793)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:4670)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4381)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3600)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2328)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9087)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1231)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
at android.view.Choreographer.doCallbacks(Choreographer.java:899)
at android.view.Choreographer.doFrame(Choreographer.java:832)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
I think you forgot to do a null check before trying to draw the bitmap