Note that there are some explanatory texts on larger screens.

plurals
  1. POAchartEngine - AddView on layout causes NullPointerException
    primarykey
    data
    text
    <p>i am trying to get rid of that error but i don't see anything wrong (for me) ; someone get that problem too but its was a bad id given to the layout : <a href="https://stackoverflow.com/questions/6318903/addview-causes-nullpointerexception">addView causes NullPointerException</a></p> <p>I took a simple code sample from <a href="http://www.javaadvent.com/2012/12/achartengine-charting-library-for.html" rel="nofollow noreferrer">http://www.javaadvent.com/2012/12/achartengine-charting-library-for.html</a></p> <pre><code>public class LineGraph extends Activity { private GraphicalView mChart; private XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset(); private XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); private XYSeries mCurrentSeries; private XYSeriesRenderer mCurrentRenderer; private void initChart() { mCurrentSeries = new XYSeries("Sample Data"); mDataset.addSeries(mCurrentSeries); mCurrentRenderer = new XYSeriesRenderer(); mRenderer.addSeriesRenderer(mCurrentRenderer); } private void addSampleData() { mCurrentSeries.add(1, 2); mCurrentSeries.add(2, 3); mCurrentSeries.add(3, 2); mCurrentSeries.add(4, 5); mCurrentSeries.add(5, 4); } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.graph); } protected void onResume() { super.onResume(); if (mChart == null) { LinearLayout layout = (LinearLayout) findViewById(R.id.chart); initChart(); addSampleData(); mChart = ChartFactory.getCubeLineChartView(this, mDataset, mRenderer, 0.3f); // Here is the problem =&gt; layout.addView(mChart); } else { mChart.repaint(); } } } </code></pre> <p>and my XML file :</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:id="@+id/chart" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>May be i missed an obvious mistake but the addView() gives me a nullPointerException, please someone can tell me what i have done wrong?</p> <p>EDIT : And the stacktrace </p> <pre><code>05-17 14:37:05.830: E/SensorManager(6703): thread start 05-17 14:37:06.885: E/SpannableStringBuilder(6703): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 05-17 14:37:06.885: E/SpannableStringBuilder(6703): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 05-17 14:37:28.800: E/AndroidRuntime(6703): FATAL EXCEPTION: main 05-17 14:37:28.800: E/AndroidRuntime(6703): java.lang.RuntimeException: Unable to resume activity {com.smartdroid/com.smartdroid.LineGraph}: java.lang.NullPointerException 05-17 14:37:28.800: E/AndroidRuntime(6703): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2616) 05-17 14:37:28.800: E/AndroidRuntime(6703): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2644) 05-17 14:37:28.800: E/AndroidRuntime(6703): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2130) 05-17 14:37:28.800: E/AndroidRuntime(6703): at android.app.ActivityThread.access$600(ActivityThread.java:140) 05-17 14:37:28.800: E/AndroidRuntime(6703): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227) 05-17 14:37:28.800: E/AndroidRuntime(6703): at android.os.Handler.dispatchMessage(Handler.java:99) 05-17 14:37:28.800: E/AndroidRuntime(6703): at android.os.Looper.loop(Looper.java:137) 05-17 14:37:28.800: E/AndroidRuntime(6703): at android.app.ActivityThread.main(ActivityThread.java:4898) 05-17 14:37:28.800: E/AndroidRuntime(6703): at java.lang.reflect.Method.invokeNative(Native Method) 05-17 14:37:28.800: E/AndroidRuntime(6703): at java.lang.reflect.Method.invoke(Method.java:511) 05-17 14:37:28.800: E/AndroidRuntime(6703): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 05-17 14:37:28.800: E/AndroidRuntime(6703): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 05-17 14:37:28.800: E/AndroidRuntime(6703): at dalvik.system.NativeStart.main(Native Method) 05-17 14:37:28.800: E/AndroidRuntime(6703): Caused by: java.lang.NullPointerException 05-17 14:37:28.800: E/AndroidRuntime(6703): at com.smartdroid.LineGraph.onResume(LineGraph.java:64) 05-17 14:37:28.800: E/AndroidRuntime(6703): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1188) 05-17 14:37:28.800: E/AndroidRuntime(6703): at android.app.Activity.performResume(Activity.java:5280) 05-17 14:37:28.800: E/AndroidRuntime(6703): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2606) 05-17 14:37:28.800: E/AndroidRuntime(6703): ... 12 more 05-17 14:38:45.465: E/SensorManager(8335): thread start 05-17 14:38:46.630: E/SpannableStringBuilder(8335): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 05-17 14:38:46.630: E/SpannableStringBuilder(8335): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload