0

运行每个图表时出现以下错误

错误日志:

10-25 06:00:46.555: E/AndroidRuntime(1307): FATAL EXCEPTION: main
10-25 06:00:46.555: E/AndroidRuntime(1307): java.lang.IllegalStateException: Could not     execute method of the activity

然后显示 eroor 日志:

10-25 06:00:46.555: E/AndroidRuntime(1307): Caused by: java.lang.reflect.InvocationTargetException
10-25 06:00:46.555: E/AndroidRuntime(1307): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 06:00:46.555: E/AndroidRuntime(1307): Caused by: java.lang.NoClassDefFoundError: org.achartengine.model.CategorySeries
10-25 06:00:46.555: E/AndroidRuntime(1307): at com.example.graph.PieGraph.getIntent(PieGraph.java:18)
10-25 06:00:46.555: E/AndroidRuntime(1307): at com.example.graph.MainActivity.pieGraphHandler(MainActivity.java:31)

饼图的类是:

包 com.example.graph;

import org.achartengine.ChartFactory;
import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;

public class PieGraph {

public Intent getIntent(Context context)
{
    int[] values = {1,2,3,4,5};

    CategorySeries series = new CategorySeries("Pie Graph");
    int k = 0;
    for(int value: values) {
        series.add("Section " + ++k, value);
    }

    int[] colors = new int[] {Color.BLUE, Color.GREEN, Color.MAGENTA, Color.YELLOW, Color.CYAN};

    DefaultRenderer renderer = new DefaultRenderer();
    for(int color: colors) {
        SimpleSeriesRenderer r = new SimpleSeriesRenderer();
        r.setColor(color);
        renderer.addSeriesRenderer(r);
    }

    Intent intent = ChartFactory.getPieChartIntent(context, series, renderer, "Pie");
    return intent;
}
}

主要活动是:

package com.example.graph;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

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

public void lineGraphHandler(View view) {
    LineGraph line = new LineGraph();
    Intent lineIntent = line.getIntent(this);
    startActivity(lineIntent);

}
public void barGraphHandler(View view) {
    BarGraph bar = new BarGraph();
    Intent lineIntent = bar.getIntent(this);
    startActivity(lineIntent);

}
public void pieGraphHandler(View view) {
    PieGraph pie = new PieGraph();
    Intent lineIntent = pie.getIntent(this);
    startActivity(lineIntent);

}
public void scatterGraphHandler(View view) {
    ScatterGraph scatter = new ScatterGraph();
    Intent lineIntent = scatter.getIntent(this);
    startActivity(lineIntent);

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

我已将 achartengine 的 jar 文件作为 achartengine-1.1.0.jar 添加到项目中,并且还添加了我的 AndroidManifest.Xml :

 <activity android:name="org.achartengine.GraphicalActivity"></activity>

当我单击每个图形作为折线图、条形图、散点图和饼图时,它给了我相同类型的错误。谁能告诉我这里有什么问题?该怎么办?

4

1 回答 1

0

再次检查以确保您确实将 AChartEngine 库添加到您的类路径中。如果您使用的是 IDE,那么清理/刷新项目可能会有所帮助。

于 2013-10-25T14:01:20.620 回答