aChartEngine神秘的IllegalArgumentException

时间:2013-08-08 18:43:32

标签: android achartengine

伙计 - 当使用aChartEngine绘制时间序列图时,我得到一个神秘的IllegalArgumentException。以下是尝试呈现图表的代码段:

private GraphicalView chartView;
private XYMultipleSeriesDataset dataset;
private XYMultipleSeriesRenderer renderers;

dataset = new XYMultipleSeriesDataset();
TimeSeries series = new TimeSeries(varLongName);
for(int i=0;i<values.size();i++) 
    series.add(quarterDates.get(i), values.get(i));
dataset.addSeries(series);

renderers = new XYMultipleSeriesRenderer();
double YMin=0f;
double YMax=0f;

XYSeriesRenderer render = new XYSeriesRenderer();
render.setColor(Color.RED);
render.setPointStyle(PointStyle.CIRCLE);
render.setFillPoints(true);
render.setLineWidth(2f);
YMin=dataset.getSeriesAt(0).getMinY();
YMax=dataset.getSeriesAt(0).getMaxY();
renderers.addSeriesRenderer(render);
renderers.setXTitle("Date");
renderers.setYTitle(varShortName);
renderers.setAxesColor(Color.GREEN);
renderers.setChartTitle(currentBankName+" "+varShortName+".");
renderers.setAxisTitleTextSize(16f);
renderers.setYLabelsAlign(Align.RIGHT);
renderers.setYLabelsPadding(5f);
renderers.setLabelsTextSize(12f);
renderers.setLegendTextSize(12f);

Log.d(TAG,"YMin is initially set to: "+YMin);
YMin -=5f;
Log.d(TAG,"YMin is now set to: "+YMin);
Log.d(TAG,"YMax is initially set to: "+YMax);
YMax +=5f;
Log.d(TAG,"YMax is now set to: "+YMax);
renderers.setYAxisMin(YMin);
Log.d(TAG, "Set YAxis Min on renderer");
renderers.setYAxisMax(YMax);
Log.d(TAG, "Set YAxis Max on renderer");

chartView = ChartFactory.getTimeChartView(this, dataset, renderers, "dd-MMM-yyyy");
Log.d(TAG, "Created chartView");
plotArea.addView(chartView, new LayoutParams(LayoutParams.MATCH_PARENT, 250));

我添加了很多调试消息来本地化问题但仍然遇到问题。从它的外观来看,似乎有些东西是-Inf或类似的东西,但我可能完全走错了轨道。我还包括活动的布局文件。

布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/background"
tools:context=".MyPerformance" >

<TextView
    android:id="@+id/HelloUser"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:layout_marginTop="5dp"
    android:textColor="@color/strong_black"
    android:textSize="16sp"
    android:textStyle="bold"
    android:layout_marginLeft="5dp" />

<TextView
    android:id="@+id/ReportForBank"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/HelloUser"
    android:layout_alignLeft="@id/HelloUser"
    android:text="@string/reportForBank"
    android:layout_marginTop="10dp"
    android:textColor="@color/strong_black"
    android:textSize="12sp"
    android:textStyle="bold" />

<Spinner
    android:id="@+id/PerfVarSpinner"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_below="@id/ReportForBank"
    android:layout_alignLeft="@id/ReportForBank"
    android:prompt="@string/var_prompt" />

<ImageView
    android:id="@+id/HelpOnVarIcon"
    android:layout_width="36dp"
    android:layout_height="36dp"
    android:layout_toRightOf="@id/PerfVarSpinner"
    android:layout_alignTop="@id/PerfVarSpinner"
    android:src="@drawable/help"
    android:contentDescription="@string/help"
    android:clickable="true"
    android:onClick="showDescription" />

<FrameLayout 
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:layout_below="@id/PerfVarSpinner"
    android:layout_alignLeft="@id/ReportForBank"
    android:background="@color/black_overlay"
    android:id="@+id/PlotArea" />

<TextView
    android:id="@+id/Recommendations"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/PlotArea"
    android:layout_alignLeft="@id/PlotArea"
    android:text="@string/recommendation"
    android:layout_marginTop="10dp"
    android:textColor="@color/strong_black"
    android:textSize="12sp"
    android:textStyle="bold" />

任何帮助将非常感激。这是logcat输出:

08-08 18:25:57.909: D/com.ssjanus.bankstats.MyPerformance(2404): YMin is initially set to: 318580.0
08-08 18:25:57.909: D/com.ssjanus.bankstats.MyPerformance(2404): YMin is now set to: 318575.0
08-08 18:25:57.909: D/com.ssjanus.bankstats.MyPerformance(2404): YMax is initially set to: 318580.0
08-08 18:25:57.919: D/com.ssjanus.bankstats.MyPerformance(2404): YMax is now set to: 318585.0
08-08 18:25:57.919: D/com.ssjanus.bankstats.MyPerformance(2404): Set YAxis Min on renderer
08-08 18:25:57.919: D/com.ssjanus.bankstats.MyPerformance(2404): Set YAxis Max on renderer
08-08 18:25:57.939: D/com.ssjanus.bankstats.MyPerformance(2404): Created chartView
08-08 18:25:58.079: D/AndroidRuntime(2404): Shutting down VM
08-08 18:25:58.079: W/dalvikvm(2404): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
08-08 18:25:58.129: E/AndroidRuntime(2404): FATAL EXCEPTION: main
08-08 18:25:58.129: E/AndroidRuntime(2404): java.lang.IllegalArgumentException: -5.585327982E13 > -1.1170655964E14
08-08 18:25:58.129: E/AndroidRuntime(2404):     at java.util.TreeMap$BoundedMap.<init>(TreeMap.java:1110)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at java.util.TreeMap.subMap(TreeMap.java:704)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at org.achartengine.model.XYSeries.getRange(XYSeries.java:305)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at org.achartengine.chart.XYChart.draw(XYChart.java:254)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at org.achartengine.GraphicalView.onDraw(GraphicalView.java:168)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.View.draw(View.java:10978)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.View.draw(View.java:10981)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.widget.FrameLayout.draw(FrameLayout.java:450)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.View.draw(View.java:10981)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.View.draw(View.java:10981)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.widget.FrameLayout.draw(FrameLayout.java:450)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewGroup.drawChild(ViewGroup.java:2885)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.View.draw(View.java:10981)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.widget.FrameLayout.draw(FrameLayout.java:450)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2126)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewRootImpl.draw(ViewRootImpl.java:2026)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1634)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.os.Looper.loop(Looper.java:137)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at android.app.ActivityThread.main(ActivityThread.java:4424)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at java.lang.reflect.Method.invokeNative(Native Method)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at java.lang.reflect.Method.invoke(Method.java:511)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-08 18:25:58.129: E/AndroidRuntime(2404):     at dalvik.system.NativeStart.main(Native Method)
08-08 18:25:58.739: I/dalvikvm(2404): threadid=3: reacting to signal 3
08-08 18:25:58.760: I/dalvikvm(2404): Wrote stack traces to '/data/anr/traces.txt'

更新:好吧,我想我在茶杯中引发了风暴!对于那个很抱歉。事实证明,日期格式错误导致了这种异常。

1 个答案:

答案 0 :(得分:1)

事实证明,日期格式错误导致此异常。我使用SimpleDateFormat将日期从sql日期格式(yyyy-MM-dd)转换为java.util.Date,这是好的,除了我抓住日期的“年”部分错误,例如,将年份设置为200而不是这引起了例外。