17

I'm designing a bar graph and a pie chart in a view pager using AChartEngine library. When I scroll from bar graph to pie chart, application crashes. The crash report is as following.

 FATAL EXCEPTION: main
 java.lang.IllegalArgumentException: radius must be > 0
    at android.graphics.RadialGradient.<init>(RadialGradient.java:58)
    at org.achartengine.chart.PieChart.draw(PieChart.java:112)
    at org.achartengine.GraphicalView.onDraw(GraphicalView.java:168)
    at android.view.View.draw(View.java:11120)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2901)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2899)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2899)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
    at android.view.View.draw(View.java:11123)
    at android.support.v4.view.ViewPager.draw(ViewPager.java:2157)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2901)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2899)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2899)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2899)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2899)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
    at android.view.View.draw(View.java:11123)
    at android.widget.FrameLayout.draw(FrameLayout.java:450)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2901)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2899)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2899)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
    at android.view.View.draw(View.java:11123)
    at android.widget.FrameLayout.draw(FrameLayout.java:450)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2276)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2210)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1816)
    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2628)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4517)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
    at dalvik.system.NativeStart.main(Native Method)

Any help to solve this will be appreciable.

madhu
  • 744
  • 3
  • 8
  • 19

3 Answers3

41

If you are having this issue on Android L (5.0), I have noticed that GradientDrawable does not accept the "%" suffix. So instead, I have used the "%p" suffix, and it works. Also, I needed to change my absurdly high value (80000%) with a normal value (80%p), and now it looks proper.

So, I have created a "drawable-v21" folder (from which Android L will take its drawables), copied my shape xml which contains the gradient and changed this line:

android:gradientRadius="80000%"

with this

android:gradientRadius="80%p"
radu122
  • 2,865
  • 24
  • 24
  • 4
    NOTE: %p stands for "relative to parent container". In document: `The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.` https://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html#attr_android:gradientRadius – ypresto Aug 10 '16 at 03:57
  • replace "80%" to "80p%" works for me in android 5.0.2 – Spark.Bao Feb 21 '17 at 03:38
  • 1
    Thanks. 2019 and this still works. This is about the weirdest quirk of the Android SDK I experienced so far. – Ivan Bartsov Nov 22 '19 at 08:25
2

In my case i added android:gradientRadius="30dp".

That dp at the end was trowing the same exception on some devices.

Leave it android:gradientRadius="30" or use the @radu122 's answer

4bottiglie
  • 523
  • 7
  • 22
  • thanks the crash is gone but the gradient dont work after removing "dp" – Hoby Aug 22 '17 at 10:32
  • 1
    try to increase it, the 30 number is in pixels, if you want to transform it in dp you can define a size with 30dp and link it: android:gradientRadius="@dimen/my_gradient_radius" – 4bottiglie Aug 23 '17 at 15:26
2

For me problem was in cardview's app:cardCornerRadius="0dp"

I changed it to :

app:cardCornerRadius="1dp"

https://stackoverflow.com/a/43864791/6055194

Eugene Babich
  • 1,271
  • 15
  • 25