-1

I need some help. I have a PieChartBuilder chart that should create a piechart using some .jar libraries.
PieChartBuilder extends Activity but when it comes to start the PieChartBuilder I get the error: NoClassDefFoundError: org.achartengine.model.CategorySeries.

This is the PieChartBuilder class:

public class PieChartBuilder extends Activity {
 /** Colors to be used for the pie slices. */

private static String[] VALORI = new String[]{"10","20","30","20","10","10"};
private static int[] COLORS = new int[] { Color.GREEN, Color.BLUE, Color.MAGENTA,     Color.CYAN };
/** The main series that will include all the data. */ // I guess the app crashes here...
private CategorySeries mSeries = new CategorySeries("");
/** The main renderer for the main dataset. */
private DefaultRenderer mRenderer = new DefaultRenderer();

/** The chart view that displays the data. */
private GraphicalView mChartView;

@Override
protected void onRestoreInstanceState(Bundle savedState) {
  super.onRestoreInstanceState(savedState);
  mSeries = (CategorySeries) savedState.getSerializable("current_series");
  mRenderer = (DefaultRenderer) savedState.getSerializable("current_renderer");
}

@Override
protected void onSaveInstanceState(Bundle outState) {
  super.onSaveInstanceState(outState);
  outState.putSerializable("current_series", mSeries);
  outState.putSerializable("current_renderer", mRenderer);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.xy_chart);

  mRenderer.setZoomButtonsVisible(true);
  mRenderer.setStartAngle(180);
  mRenderer.setDisplayValues(true);
 initChart();
} 


@Override
protected void onResume() {
  super.onResume();
  if (mChartView == null) {
    LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
    mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
    mRenderer.setClickEnabled(true);
    mChartView.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
          SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
          if (seriesSelection == null) {
          Toast.makeText(PieChartBuilder.this, "No chart element selected", Toast.LENGTH_SHORT)
            .show();
        } else {
        for (int i = 0; i < mSeries.getItemCount(); i++) {
          mRenderer.getSeriesRendererAt(i).setHighlighted(i == seriesSelection.getPointIndex());
        }
        mChartView.repaint();
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //setContentView(R.layout.activity_dialog);
        Toast.makeText(
            PieChartBuilder.this,
            "Chart data point index " + seriesSelection.getPointIndex() + " selected"
                + " point value=" + seriesSelection.getValue(), Toast.LENGTH_SHORT).show();
      }
    }
  });
  layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT,
      LayoutParams.FILL_PARENT));
} else {
  mChartView.repaint();
 }
}

 private void initChart(){
      int i=0;
      double value=0;
      for (String doubleString:VALORI){

          try {
           value = Double.parseDouble(doubleString);
          } catch (NumberFormatException e) {
     //            return;
          }
          mSeries.add("Series " + (mSeries.getItemCount() + 1), value);
          SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
          renderer.setColor(COLORS[i%4]);
          i++;
          mRenderer.addSeriesRenderer(renderer);
        }

      }
  }

Why I obtain that error? why does my app crash on with the NoClassDefFoundError?

What should I do?

Bhavin Nattar
  • 3,189
  • 2
  • 22
  • 30
tonix
  • 6,671
  • 13
  • 75
  • 136
  • 1
    Try importing library as project, download from here https://github.com/ncgmoviles/achartengine . – keshav Mar 19 '14 at 04:48

1 Answers1

1

Right click on your project -> Propierties -> Android

Add the library in that window, then the jar file will be automatically imported into the project settings. If doing that won't let you see the classes in the library, just add it to the build path.

Hope this works for you.

//Edit

Check the screenshot, you might have to import the project into eclipse after doing that, regards

enter image description here

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
  • Sorry, I have tried what you say but in the Android tab you can't add any new library... – tonix Mar 18 '14 at 15:17