title: achartengine cause null pointer
body: <p>I have issue regarding package org.achartengine (both available versions 1.2.0 and 1.1.0). </p>
  
  <p>In my application I call new activity, pass on parameters and then fill data for graph.</p>
  
  <p>All this is in same class:</p>
  
  <pre><code>private void showChart(CustomerTransactionModel ctm, String title) {
      try {
          if (ctm==null || ctm.getTransactionGroup()==null || 
                  ctm.getTransactionGroup().getTransactionTemplate()==null || 
                  ctm.getTransactionGroup().getTransactionTemplate().getAxisXProperty()==null ||
                  ctm.getTransactionGroup().getTransactionTemplate().getAxisYProperty()==null ||
                  ctm.getTransactionGroup().getTransactions()==null) {
              return;
          }
          String xKey=ctm.getTransactionGroup().getTransactionTemplate().getAxisXProperty();
          String yKey=ctm.getTransactionGroup().getTransactionTemplate().getAxisYProperty();
  
          ArrayList&lt;String[]&gt; v = new ArrayList&lt;String[]&gt;();
          for (Transaction tran : ctm.getTransactionGroup().getTransactions()) {
              if (tran!=null &amp;&amp; tran.getServiceData()!=null) {
                  Map&lt;Object, Object&gt; serviceData = tran.getServiceData();
  
                  if (serviceData.containsKey(xKey) &amp;&amp; serviceData.containsKey(yKey)) {
                      String[] add=new String[2];
                      add[0]=serviceData.get(xKey).toString();
                      add[1]=serviceData.get(yKey).toString();
  
                      v.add(add);
                  }
              }
          }
          if (!v.isEmpty()) {
              openChartDialog(v, title, xKey, yKey);
          }
      } catch (Exception e) {
          logger.error(e.getLocalizedMessage(), e);
      }
  }
  
  private void openChartDialog(ArrayList&lt;String[]&gt; v, String title, String xLabel, String yLabel) {
      try {
          Object[] objects=new Object[4];
          objects[0]=xLabel;
          objects[1]=yLabel;
          objects[2]=title;
          objects[3]=v;
          OpeningChartTask task = new OpeningChartTask();
          task.doInBackground(objects);
  
      } catch (Exception e) {
          logger.error(e.getLocalizedMessage(), e);
      }
  }
  
  private class OpeningChartTask extends AsyncTask&lt;Object, Object, Object&gt; {
      @Override
      protected Object doInBackground(Object... params) {
          String xLabel=(String) params[0];
          String yLabel=(String) params[1];
          String title=(String) params[2];
          ArrayList&lt;String[]&gt; v=(ArrayList&lt;String[]&gt;) params[3];
  
          Intent intent = new Intent(getActivity(), ChartDialogActivity.class);
          intent.putExtra("xLabel", xLabel);
          intent.putExtra("yLabel", yLabel);
          intent.putExtra("title", title);
          intent.putExtra("values", v);
          startActivityForResult(intent, 0);
          return null;
      }
  }
  </code></pre>
  
  <p>So far so good. In on create, I read those data (they are set successfuly) and then call method openBarChart() that contains this:</p>
  
  <pre><code>private void openBarChart() {
      // Create XY Series for X Series.
      XYSeries xSeries = new XYSeries("X series");
      // Adding data to the X Series.
      for (int i = 0; i &lt; _data.size(); i++) {
          xSeries.add(Double.parseDouble(_data.get(i)[0]),
                  Double.parseDouble(_data.get(i)[1]));
      }
  
      // Create XYSeriesRenderer to customize XSeries
      XYSeriesRenderer Xrenderer = new XYSeriesRenderer();
      Xrenderer.setColor(Color.GREEN);
      Xrenderer.setChartValuesTextSize(20);
      Xrenderer.setPointStyle(PointStyle.DIAMOND);
      Xrenderer.setDisplayChartValues(false);
      Xrenderer.setLineWidth(2);
      Xrenderer.setFillPoints(true);
  
      // Create XYMultipleSeriesRenderer to customize the whole chart
      final XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
  
      mRenderer.setChartTitle("X Vs Y Chart");
      mRenderer.setXTitle("X Values");
      mRenderer.setYTitle("Y Values");
      mRenderer.setZoomButtonsVisible(false);
      mRenderer.setXLabels(0);
      mRenderer.setPanEnabled(true);
      mRenderer.setAntialiasing(true);
      mRenderer.setBackgroundColor(Color.DKGRAY);
      mRenderer.setApplyBackgroundColor(true);
      mRenderer.setBarWidth(20);
      mRenderer.setScale((float) 0.3);
  
      mRenderer.setShowGrid(true);
  
      mRenderer.setClickEnabled(true);
  
      for (int i = 0; i &lt; _data.size(); i++) {
          mRenderer.addXTextLabel(i, _data.get(i)[0]);
      }
  
      // Adding the XSeriesRenderer to the MultipleRenderer.
      mRenderer.addSeriesRenderer(Xrenderer);
  
      LinearLayout chart_container = (LinearLayout) findViewById(R.id.chartLayoutTest);
  
      // Create a Dataset to hold the XSeries.
      XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
  
      // Add X series to the Dataset.
      dataset.addSeries(xSeries);
  
      // Creating an intent to plot line chart using dataset and
      // multipleRenderer
      final GraphicalView mChart;
      mChart = (GraphicalView) ChartFactory.getBarChartView(this, dataset,
              mRenderer, BarChart.Type.DEFAULT);
  
      // Add the graphical view mChart object into the Linear layout .
      chart_container.removeAllViews();
      chart_container.addView(mChart);
      if (mChart != null) {
          mChart.repaint();
      }
  }
  </code></pre>
  
  <p>This method also survive but when it should be shown on screen it throws error and app die.</p>
  
  <p>stacktrace is below:</p>
  
  <pre><code>E/ExceptionHandler( 8461): [uncaughtException] &gt; ************ CAUSE OF ERROR ************
  E/ExceptionHandler( 8461): 
  E/ExceptionHandler( 8461): java.lang.NullPointerException
  E/ExceptionHandler( 8461):  at java.util.TreeMap$BoundedMap.&lt;init&gt;(TreeMap.java:1115)
  E/ExceptionHandler( 8461):  at java.util.TreeMap.headMap(TreeMap.java:713)
  E/ExceptionHandler( 8461):  at  org.achartengine.model.XYSeries.getRange(XYSeries.java:310)
  E/ExceptionHandler( 8461):  at org.achartengine.chart.XYChart.draw(XYChart.java:261)
  E/ExceptionHandler( 8461):  at org.achartengine.GraphicalView.onDraw(GraphicalView.java:181)
  E/ExceptionHandler( 8461):  at android.view.View.draw(View.java:13826)
  E/ExceptionHandler( 8461):  at android.view.View.draw(View.java:13710)
  E/ExceptionHandler( 8461):  at android.view.ViewGroup.drawChild(ViewGroup.java:2988)
  E/ExceptionHandler( 8461):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2858)
  E/ExceptionHandler( 8461):  at android.view.View.draw(View.java:13829)
  E/ExceptionHandler( 8461):  at android.view.View.draw(View.java:13710)
  E/ExceptionHandler( 8461):  at android.view.ViewGroup.drawChild(ViewGroup.java:2988)
  E/ExceptionHandler( 8461):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2858)
  E/ExceptionHandler( 8461):  at android.view.View.draw(View.java:13829)
  E/ExceptionHandler( 8461):  at android.view.View.draw(View.java:13710)
  E/ExceptionHandler( 8461):  at android.view.ViewGroup.drawChild(ViewGroup.java:2988)
  E/ExceptionHandler( 8461):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2858)
  E/ExceptionHandler( 8461):  at android.view.View.draw(View.java:13708)
  E/ExceptionHandler( 8461):  at android.view.ViewGroup.drawChild(ViewGroup.java:2988)
  E/ExceptionHandler( 8461):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2858)
  E/ExceptionHandler( 8461):  at android.view.View.draw(View.java:13708)
  E/ExceptionHandler( 8461):  at android.view.ViewGroup.drawChild(ViewGroup.java:2988)
  E/ExceptionHandler( 8461):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2858)
  E/ExceptionHandler( 8461):  at android.view.View.draw(View.java:13829)
  E/ExceptionHandler( 8461):  at android.widget.FrameLayout.draw(FrameLayout.java:467)
  E/ExceptionHandler( 8461):  at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2458)
  E/ExceptionHandler( 8461):  at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2382)
  E/ExceptionHandler( 8461):  at android.view.ViewRootImpl.draw(ViewRootImpl.java:2275)
  E/ExceptionHandler( 8461):  at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2143)
  E/ExceptionHandler( 8461):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1954)
  E/ExceptionHandler( 8461):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1108)
  E/ExceptionHandler( 8461):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4491)
  E/ExceptionHandler( 8461):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:755)
  E/ExceptionHandler( 8461):  at android.view.Choreographer.doCallbacks(Choreographer.java:585)
  E/ExceptionHandler( 8461):  at android.view.Choreographer.doFrame(Choreographer.java:555)
  E/ExceptionHandler( 8461):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:741)
  E/ExceptionHandler( 8461):  at android.os.Handler.handleCallback(Handler.java:615)
  E/ExceptionHandler( 8461):  at android.os.Handler.dispatchMessage(Handler.java:92)
  E/ExceptionHandler( 8461):  at android.os.Looper.loop(Looper.java:137)
  E/ExceptionHandler( 8461):  at android.app.ActivityThread.main(ActivityThread.java:4949)
  E/ExceptionHandler( 8461):  at java.lang.reflect.Method.invokeNative(Native Method)
  E/ExceptionHandler( 8461):  at java.lang.reflect.Method.invoke(Method.java:511)
  E/ExceptionHandler( 8461):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043)
  E/ExceptionHandler( 8461):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
  E/ExceptionHandler( 8461):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Any help would be much appreciated!</p>
  
  <p>Oh and this, I did the work and checked content of those .java files and found couple of "tweaks" but I guess it's me that working something wrong here. If I make new project I can normally use this jar, the only difference is that previously I imported jar but now I'm calling this jar with maven pom file (I have my own repository but it should work ok anyway).</p>
  
  <p>Thank you!</p>
  
  <p><strong>***SOLUTION FOUND***</strong></p>
  
  <p>In class org.achartengine.model.XYSeries I created simple Comparator and passed it to both TreeMap constructors. Then I changed constructor in org.achartengine.util.IndexXYMap to accept coparator and passed on to super(comparator).</p>
  
  <p>I don't know exactly yet why this happened in one project and it didn't in previous so I'll leave question open, if anyone has explanation for this.</p>
  
  <p>Thank you @keshav for your efforts.</p>