IllegalArgumentException:radius必须是> 0

时间:2014-02-06 14:39:20

标签: android android-viewpager achartengine

我正在使用AChartEngine库在视图寻呼机中设计条形图和饼图。当我从条形图滚动到饼图时,应用程序崩溃。崩溃报告如下。

 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)

任何帮助解决这个问题都会很明显。

3 个答案:

答案 0 :(得分:31)

如果您在Android L(5.0)上遇到此问题,我注意到GradientDrawable不接受“%”后缀。所以相反,我使用了“%p”后缀,它的工作原理。另外,我需要用正常值(80%p)改变我荒谬的高值(80000%),现在它看起来很合适。

所以,我创建了一个“drawable-v21”文件夹(Android L将从中获取其drawable),复制我的形状xml,其中包含渐变并更改了这一行:

android:gradientRadius="80000%"

用这个

android:gradientRadius="80%p"

答案 1 :(得分:2)

在我的情况下,我添加了android:gradientRadius="30dp"

最后dp在某些设备上投了同样的例外。

保留android:gradientRadius="30"或使用@ radu122的回答

答案 2 :(得分:0)

对我来说,问题出在Cardview的app:cardCornerRadius="0dp" https://stackoverflow.com/a/43864791/6055194