title: MPAndroid does not show the pie chart
body: <p>I want to display a pie chart using the data from the sqlite. I out the data into the list to have the entries for the pie chart. But it seems something is wrong with the code and I don;t know what is wrong with it.Below is the code.</p>
  
  <pre><code>public class chart extends Activity {
  
  SQLiteDatabase SQ;
  
  @Override
  protected void onCreate (Bundle savedInstanceState){
  …
      //add data
      addData();
  
      //customize legends
      Legend l=mChart.getLegend();
      l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
      l.setXEntrySpace(7);
      l.setYEntrySpace(5);
  
  }
  
  public ArrayList&lt;String&gt; queryXData(){
      ArrayList&lt;String&gt; xNewData = new ArrayList&lt;String&gt;();
      String query="SELECT "+ TableInfo.APPLIANCE +" FROM "+TableInfo.TABLE_NAME;
      Cursor cursor = SQ.rawQuery(query,null);
      for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){
          xNewData.add(cursor.getString(0));
      }
      cursor.close();
      return xNewData;
  }
  
  public ArrayList&lt;Integer&gt; queryYData(){
      ArrayList&lt;Integer&gt; yNewData= new ArrayList&lt;Integer&gt;();
      String query="SELECT "+ TableInfo.POWER_USED +" FROM "+TableInfo.TABLE_NAME;
      Cursor cursor=SQ.rawQuery(query,null);
      for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){
          yNewData.add(cursor.getInt(5));
      }
      cursor.close();
      return yNewData;
  }
  
  private void addData() {
      ArrayList&lt;Entry&gt; yVals = new ArrayList&lt;Entry&gt;();
  
      for (int i = 0; i &lt; queryYData().size(); i++)
          yVals.add(new Entry(queryYData().get(i), i));
  
      ArrayList&lt;String&gt; xVals = new ArrayList&lt;String&gt;();
  
      for (int i = 0; i &lt; queryXData().size(); i++)
          xVals.add(queryXData().get(i));
  
      //create pie data set
      PieDataSet dataSet=new PieDataSet(yVals,"Appliances");
      dataSet.setSliceSpace(3); // space between each arc slice
      dataSet.setSelectionShift(5);
  
      //add many colors
      ArrayList&lt;Integer&gt; colors=new ArrayList&lt;Integer&gt;();
  
      for(int c: ColorTemplate.VORDIPLOM_COLORS)
          colors.add(c);
      for(int c: ColorTemplate.JOYFUL_COLORS)
          colors.add(c);
      for(int c: ColorTemplate.COLORFUL_COLORS)
          colors.add(c);
      for(int c: ColorTemplate.LIBERTY_COLORS)
          colors.add(c);
      for(int c: ColorTemplate.PASTEL_COLORS)
          colors.add(c);
      colors.add(ColorTemplate.getHoloBlue());
      dataSet.setColors(colors);
  
      //instantiate pie data object now
      PieData data=new PieData(xVals, dataSet);
      data.setValueFormatter(new PercentFormatter());
      data.setValueTextSize(11f);
      data.setValueTextColor(Color.GRAY);
  
      mChart.setData(data);
  
      //undo all highlights
      mChart.highlightValues(null);
  
      //update pie chart
      mChart.invalidate();
  
      //demo start
  }
  
  }
  </code></pre>
  
  <p>Aboce is the code I tried , but there are errors, mainly </p>
  
  <blockquote>
    <p>chart.queryYData(chart.java:100) <code>Cursor cursor=SQ.rawQuery(query,null);</code>
    chart.addData(chart.java:111)     <code>for (int i = 0; i &lt; queryYData().size(); i++)</code>
    chart.onCreate(chart.java:76)    <code>addData();</code></p>
  </blockquote>
  
  <p>These error made the app “Unfortunaely, app has stopped.”. Can someone help me with this? Thank you.</p>