Hi!

I want to create a LineChart in the fly and add it to a LinearLayout.

I do it like this:

- create a XYSeries and add all the data I need.
- create a XYMultipleSeriesDataset and add the XYSeries instance
- create a SimpleSeriesRenderer
- create a XYMultipleSeriesRenderer and add it the SimpleSeriesRenderer instance.
- create the LineChart using the XYMultipleSeriesDataset and XYMultipleSeriesRenderer instances.
- create a GraphicalView using the applicationcontext and and LineChart instance.
- add the view to the LinearLayout

Then I add some other views to the linearlayout.

The code does pass over all of this but then it fails in another thread before I get to see any of the things I added (not to mention the chart) and it's a problem related to a class casting exception.

Code:
12-06 16:46:18.561: E/AndroidRuntime(1228): FATAL EXCEPTION: main
12-06 16:46:18.561: E/AndroidRuntime(1228): java.lang.ClassCastException: org.achartengine.renderer.SimpleSeriesRenderer cannot be cast to org.achartengine.renderer.XYSeriesRenderer
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at org.achartengine.chart.LineChart.drawSeries(LineChart.java:79)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at org.achartengine.chart.XYChart.drawSeries(XYChart.java:486)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at org.achartengine.chart.XYChart.draw(XYChart.java:286)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at org.achartengine.GraphicalView.onDraw(GraphicalView.java:166)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.View.draw(View.java:13458)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.View.draw(View.java:13342)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.View.draw(View.java:13340)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.View.draw(View.java:13461)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.widget.FrameLayout.draw(FrameLayout.java:467)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.widget.ScrollView.draw(ScrollView.java:1555)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.View.draw(View.java:13342)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.View.draw(View.java:13340)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.View.draw(View.java:13461)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.widget.FrameLayout.draw(FrameLayout.java:467)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.View.draw(View.java:13342)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.View.draw(View.java:13340)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.View.draw(View.java:13461)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.widget.FrameLayout.draw(FrameLayout.java:467)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2183)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2256)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewRootImpl.draw(ViewRootImpl.java:2151)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2019)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1830)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.Choreographer.doCallbacks(Choreographer.java:555)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.Choreographer.doFrame(Choreographer.java:525)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.os.Handler.handleCallback(Handler.java:615)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.os.Handler.dispatchMessage(Handler.java:92)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.os.Looper.loop(Looper.java:137)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at android.app.ActivityThread.main(ActivityThread.java:4745)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at java.lang.reflect.Method.invokeNative(Native Method)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at java.lang.reflect.Method.invoke(Method.java:511)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-06 16:46:18.561: E/AndroidRuntime(1228): 	at dalvik.system.NativeStart.main(Native Method)
I am double checking the classes needed for every achartengine call and they are all right so what's going on? A bug in achartengime? Am I missing something?

Thanks in advance.

- - - Updated - - -

This is very interesting. If I don't add anything else to the linear layout where I'm including the chart, there's no exception.... why is that?

PS Also, I don't get to see the chart at all so I guess I'm missing something when I create the LineChart.