我正在尝试使用achartengine样本饼图代码中的代码。在添加代码和库时,应用程序崩溃。我添加了这个库:achartengine-1.0.0.jar
使用Buildpath - >配置构建路径 - > libraries - >添加外部jar。
但是这个库是在引用的库中显示而不是在eclipse的私有库中显示。 我在样本中使用了这段代码:
code = new String[] {
"Eclair & Older", "Froyo", "Gingerbread", "Honeycomb",
"IceCream Sandwich", "Jelly Bean"
};
// Pie Chart Slice Values
double[] distribution = { 3.9, 12.9, 55.8, 1.9, 23.7, 1.8 } ;
// Color of each Pie Chart Slices
int[] colors = { Color.BLUE, Color.MAGENTA, Color.GREEN, Color.CYAN, Color.RED,
Color.YELLOW };
// Instantiating CategorySeries to plot Pie Chart
CategorySeries distributionSeries = new CategorySeries(" Android version distribution as on October 1, 2012");
for(int i=0 ;i < distribution.length;i++){
// Adding a slice with its values and name to the Pie Chart
distributionSeries.add(code[i], distribution[i]);
}
// Instantiating a renderer for the Pie Chart
DefaultRenderer defaultRenderer = new DefaultRenderer();
for(int i = 0 ;i<distribution.length;i++){
// Instantiating a render for the slice
SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();
seriesRenderer.setColor(colors[i]);
seriesRenderer.setDisplayChartValues(true);
// Adding the renderer of a slice to the renderer of the pie chart
defaultRenderer.addSeriesRenderer(seriesRenderer);
}
defaultRenderer.setChartTitle("Android version distribution as on October 1, 2012 ");
defaultRenderer.setChartTitleTextSize(20);
defaultRenderer.setZoomButtonsVisible(true);
// Getting a reference to view group linear layout chart_container
// Getting PieChartView to add to the custom layout
mChart = ChartFactory.getPieChartView(getBaseContext(), distributionSeries, defaultRenderer);
// Adding the pie chart to the custom layout
contentView.addView(mChart);
并且应用程序崩溃并显示此错误:
12-09 11:23:14.356: E/dalvikvm(354): Could not find class 'org.achartengine.model.CategorySeries', referenced from method com.example.aimpaas.MainActivity$2$1.onClick
12-09 11:23:14.356: W/dalvikvm(354): VFY: unable to resolve new-instance 824 (Lorg/achartengine/model/CategorySeries;) in Lcom/example/aimpaas/MainActivity$2$1;
12-09 11:23:14.356: D/dalvikvm(354): VFY: replacing opcode 0x22 at 0x00e7
12-09 11:23:14.356: D/dalvikvm(354): VFY: dead code 0x00e9-0136 in Lcom/example/aimpaas/MainActivity$2$1;.onClick (Landroid/view/View;)V
12-09 11:23:14.356: D/dalvikvm(354): VFY: dead code 0x01a0-01cd in Lcom/example/aimpaas/MainActivity$2$1;.onClick (Landroid/view/View;)V
12-09 11:23:15.726: D/AndroidRuntime(354): Shutting down VM
12-09 11:23:15.726: W/dalvikvm(354): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-09 11:23:15.726: E/AndroidRuntime(354): FATAL EXCEPTION: main
12-09 11:23:15.726: E/AndroidRuntime(354): java.lang.NoClassDefFoundError: org.achartengine.model.CategorySeries
12-09 11:23:15.726: E/AndroidRuntime(354): at com.example.aimpaas.MainActivity$2$1.onClick(MainActivity.java:229)
12-09 11:23:15.726: E/AndroidRuntime(354): at android.view.View.performClick(View.java:2408)
12-09 11:23:15.726: E/AndroidRuntime(354): at android.view.View$PerformClick.run(View.java:8816)
12-09 11:23:15.726: E/AndroidRuntime(354): at android.os.Handler.handleCallback(Handler.java:587)
12-09 11:23:15.726: E/AndroidRuntime(354): at android.os.Handler.dispatchMessage(Handler.java:92)
12-09 11:23:15.726: E/AndroidRuntime(354): at android.os.Looper.loop(Looper.java:123)
12-09 11:23:15.726: E/AndroidRuntime(354): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-09 11:23:15.726: E/AndroidRuntime(354): at java.lang.reflect.Method.invokeNative(Native Method)
12-09 11:23:15.726: E/AndroidRuntime(354): at java.lang.reflect.Method.invoke(Method.java:521)
12-09 11:23:15.726: E/AndroidRuntime(354): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-09 11:23:15.726: E/AndroidRuntime(354): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-09 11:23:15.726: E/AndroidRuntime(354): at dalvik.system.NativeStart.main(Native Method)
12-09 11:23:17.797: I/Process(354): Sending signal. PID: 354 SIG: 9
答案 0 :(得分:2)
在“订购和导出”选项卡中检查该jar并运行。
答案 1 :(得分:1)
我从java构建路径中删除了android依赖项,然后清理并重建了一个项目(这对我来说很有用)。