NoClassDefFoundError:org.achartengine.model.CategorySeries,为什么我不能绘制PieChart?

时间:2014-03-18 11:37:57

标签: java android achartengine pie-chart

我需要一些帮助。我有一个PieChartBuilder chart应该使用一些.jar libraries创建一个饼图。
PieChartBuilder extends Activity但是当启动PieChartBuilder时,我收到错误:NoClassDefFoundError: org.achartengine.model.CategorySeries.

这是PieChartBuilder类:

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);
        }

      }
  }

为什么我会收到该错误?为什么我的应用程序崩溃了NoClassDefFoundError?

我该怎么办?

1 个答案:

答案 0 :(得分:1)

右键点击您的项目 - &gt; Propierties - &gt; Android

在该窗口中添加库,然后jar文件将自动导入到项目设置中。如果这样做不会让你看到库中的类,只需将它添加到构建路径。

希望这适合你。

//修改

检查屏幕截图,您可能必须在执行此操作后将项目导入eclipse,问候

enter image description here