diogobernardino / williamchart

Android Library to rapidly develop attractive and insightful charts in android applications.
5.1k stars 800 forks source link

IndexOutOfBounds error when trying to show a LineChart #212

Closed ardevd closed 7 years ago

ardevd commented 7 years ago

Im filling up a LineSet with strings and floats and when trying to show the LineChart I get the following error:

09-14 23:15:57.246  5607  5607 E AndroidRuntime: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at java.util.ArrayList.get(ArrayList.java:437)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at com.db.chart.renderer.AxisRenderer.extractLabels(AxisRenderer.java:327)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at com.db.chart.renderer.AxisRenderer.init(AxisRenderer.java:132)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at com.db.chart.view.ChartView$1.onPreDraw(ChartView.java:171)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2337)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.view.Choreographer.doCallbacks(Choreographer.java:723)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.view.Choreographer.doFrame(Choreographer.java:658)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:789)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:98)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:164)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6541)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
09-14 23:15:57.246  5607  5607 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Any idea what might be wrong?

diogobernardino commented 7 years ago

Are you passing that lineset to the chart afterwards?

ardevd commented 7 years ago

Haha! Of course. I can't believe I forgot that. I'm terribly sorry. I was up way too late coding for too long. Thanks for an awesome library.

hi-manshu commented 7 years ago

what was the solution can you please let me knwo

diogobernardino commented 7 years ago

I believe @ardevd just needed to add a dataset to his chart.

ardevd commented 7 years ago

@hi-manshu Indeed, I basically forgot this line:

lineChart.addData(dataset);