title: Android MP Chart highlightValue not working, throws ArrayIndexOutOfBoundsException
body: <p>I'm playing around with Android <a href="https://github.com/PhilJay/MPAndroidChart" rel="nofollow noreferrer">MP Chart</a> lib to draw awesome charts.</p>
  
  <p>I'm trying to highlight values on my chart, but it <strong>does not puts the highlight to the right place</strong>, or throws <strong>ArrayIndexOutOfBoundsException</strong>.</p>
  
  <p>I've made a little dummy project for it. When user clicks on the next button, <strong>the highlight should move to positive direction.</strong></p>
  
  <pre><code>  public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  
      final int DATA_MAX_COUNT = 30;
  
      List&lt;MyData&gt; list    = new ArrayList&lt;&gt;(); ///&lt;Dummy data stored in here
      List&lt;Entry&gt;  entries = new ArrayList&lt;&gt;(); ///&lt;Entries for MP Chart
  
      int highlightIndex = 0; ///&lt;Chart's data index to be highlighted
  
      CombinedChart combinedChart; ///&lt;I use combined chart because there will be more data sets added later on
  
      Button prevBtn; ///&lt;Button for highlight control
      Button nextBtn; ///&lt;Button for highlight control
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          combinedChart = (CombinedChart) findViewById(R.id.chart);
  
          prevBtn = (Button) findViewById(R.id.prev_btn);
          prevBtn.setOnClickListener(this);
  
          nextBtn = (Button) findViewById(R.id.next_btn);
          nextBtn.setOnClickListener(this);
  
          generateData();
          drawChart();
      }
  
  
      @Override
      public void onClick(View v) {
  
          //Clicking buttons should move the highlighted value
          if (v.equals(prevBtn)) {
              if (highlightIndex &gt; 0) {
                  highlightIndex--;
              }
          } else if (v.equals(nextBtn)) {
              if (highlightIndex + 1 &lt; DATA_MAX_COUNT) {
                  highlightIndex++;
              }
          }
  
          //Does not work, throws exception
          //combinedChart.highlightValue(new Highlight(highlightIndex, 0, 0));
  
          //Does not work, throws exception
          //combinedChart.highlightValue(highlightIndex, 0, false);
  
          //Exception
  
  //        java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1
  //        at com.github.mikephil.charting.data.CombinedData.getDataByIndex(CombinedData.java:152)
  //        at com.github.mikephil.charting.data.CombinedData.getEntryForHighlight(CombinedData.java:183)
  //        at com.github.mikephil.charting.charts.Chart.highlightValue(Chart.java:635)
  //        at com.github.mikephil.charting.charts.Chart.highlightValue(Chart.java:613)
  
  
          //Works, but highlights value on chart with like x=0 and y= 190, wtf?
          combinedChart.highlightValue(combinedChart.getHighlighter().getHighlight(highlightIndex, 0));
  
  
      }
  
  
      //Generating random data to a list
      public void generateData() {
          for (int i = 0; i &lt; DATA_MAX_COUNT; i++) {
              MyData myData = new MyData(new Random().nextInt(100) + 100);
              list.add(myData);
          }
      }
  
      //Simple func for adding data to entries and drawing chart
      private void drawChart() {
  
          CombinedData combinedData = new CombinedData();
  
          for (int i = 0; i &lt; list.size(); i++) {
              MyData myData = list.get(i);
              entries.add(new Entry(i, myData.getValue(), myData));
          }
  
          LineDataSet lineDataSet = new LineDataSet(entries, "My data list");
  
          lineDataSet.setHighLightColor(Color.RED);
          lineDataSet.setHighlightLineWidth(3);
  
          LineData lineData = new LineData();
          lineData.addDataSet(lineDataSet);
  
          combinedData.setData(lineData);
          combinedChart.setData(combinedData);
  
          combinedChart.invalidate();
      }
  
  
      //Dummy data class
      public static class MyData {
  
          private int value;
  
          public MyData(int value) {
              this.value = value;
          }
  
          public int getValue() {
              return value;
          }
  
          public void setValue(int value) {
              this.value = value;
          }
      }
  }
  </code></pre>
  
  <p>I don't get it why I'm getting</p>
  
  <blockquote>
    <p>java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1</p>
  </blockquote>
  
  <p>Because what the hell is <strong>-1</strong>? and what is <strong>10</strong>? There are n<strong>ot a single thing in my code which is 10</strong>, and why does any of the <strong>chart's functions getting -1?</strong></p>
  
  <p>I'm using </p>
  
  <blockquote>
    <p>com.github.PhilJay:MPAndroidChart:v3.0.3</p>
  </blockquote>
  
  <p>Please help if you can.</p>
  
  <p><strong>E D I T:</strong></p>
  
  <p>I've added  <code>combinedChart.setOnChartValueSelectedListener(this);</code> to the chart.</p>
  
  <p>With this callback <code>onValueSelected(Entry, Highlight)</code> I can test this thing in another way. It gives a Highlight object. If I does nothing in this callback, the chart draws the highlights well. If I call it programatically with the same X value, it throws the usual exception or draws the highlight to wrong position. (to zero)</p>
  
  <p>See the callback:</p>
  
  <pre><code> @Override
      public void onValueSelected(Entry e, Highlight h) {
          float x = h.getX();
  
          Log.i("Highlighted", "Actual highlight: " + x);
  
          //Getting the same exception as above
          //combinedChart.highlightValue(x, 0, false);
  
          //Does not works, draws to x=0 position with any given x
          combinedChart.highlightValue(combinedChart.getHighlighter().getHighlight(x, 0));
      }
  </code></pre>