当我运行每个图形时,我发生了以下错误
错误日志:
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)
饼图的类是:
package 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>
当我将每个图形单击为折线图,条形图,散点图和饼图时,它给出了相同类型的错误。谁能告诉我这里有什么问题?怎么办?
答案 0 :(得分:0)
再次检查以确保您确实已将AChartEngine库添加到类路径中。如果您使用的是IDE,则项目清理/刷新可能有所帮助。