gpt4 book ai didi

android - Classcastexception图表引擎

转载 作者:搜寻专家 更新时间:2023-11-01 08:57:18 24 4
gpt4 key购买 nike

我正在尝试从以下 link 运行 achartengine 示例得到一个Classcastexception。无法找到问题的根源。我添加了 mainactivity.java 和 manifest.xml。任何帮助表示赞赏。

08-09 04:08:10.370: E/AndroidRuntime(3350): FATAL EXCEPTION: main
08-09 04:08:10.370: E/AndroidRuntime(3350): java.lang.ClassCastException: org.achartengine.renderer.SimpleSeriesRenderer cannot be cast to org.achartengine.renderer.XYSeriesRenderer

主 Activity .java

public class MainActivity extends Activity {

private static final int SERIES_NR = 2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
XYMultipleSeriesRenderer renderer = getTruitonBarRenderer();
myChartSettings(renderer);
Intent intent = ChartFactory.getBarChartIntent(this,
getTruitonBarDataset(), renderer, Type.DEFAULT);
startActivity(intent);
}

private XYMultipleSeriesDataset getTruitonBarDataset() {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
final int nr = 4;
Random r = new Random();
ArrayList<String> legendTitles = new ArrayList<String>();
legendTitles.add("Sales");
legendTitles.add("Expenses");
for (int i = 0; i < SERIES_NR; i++) {
CategorySeries series = new CategorySeries(legendTitles.get(i));
for (int k = 0; k < nr; k++) {
series.add(100 + r.nextInt() % 100);
}
dataset.addSeries(series.toXYSeries());
}
return dataset;
}

public XYMultipleSeriesRenderer getTruitonBarRenderer() {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(16);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setMargins(new int[] { 30, 40, 15, 0 });
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(Color.BLUE);
renderer.addSeriesRenderer(r);
r = new SimpleSeriesRenderer();
r.setColor(Color.RED);
renderer.addSeriesRenderer(r);
return renderer;
}

private void myChartSettings(XYMultipleSeriesRenderer renderer) {
renderer.setChartTitle("Truiton's Performance by AChartEngine BarChart");
renderer.setXAxisMin(0.5);
renderer.setXAxisMax(10.5);
renderer.setYAxisMin(0);
renderer.setYAxisMax(210);
renderer.addXTextLabel(1, "2010");
renderer.addXTextLabel(2, "2011");
renderer.addXTextLabel(3, "2012");
renderer.addXTextLabel(4, "2013");
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setBarSpacing(0.5);
renderer.setXTitle("Years");
renderer.setYTitle("Performance");
renderer.setShowGrid(true);
renderer.setGridColor(Color.GRAY);
renderer.setXLabels(0);
}
}

list .xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.piegraphicsview"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.piegraphicsview.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="org.achartengine.GraphicalActivity" >
</activity>
</application>

</manifest>

最佳答案

我刚刚遇到了类似的问题,解决方案如@developeralways 所说,使用 XYSeriesRenderer 而不是 SimpleSeriesRenderer,虽然我使用 SimpleSeriesRenderer 时没有编译错误并且它在我更新到版本之后(achartengine 1.0.0)之前工作1.2.0,它不再工作了。

renderer = new XYMultipleSeriesRenderer();
SimpleSeriesRenderer renderBar = new SimpleSeriesRenderer();
renderBar.setColor(StandardColor.BLUE);
renderer.addSeriesRenderer(renderBar);

更改为:

renderer = new XYMultipleSeriesRenderer();
SimpleSeriesRenderer renderBar = new XYSeriesRenderer();
renderBar.setColor(StandardColor.BLUE);
renderer.addSeriesRenderer(renderBar);

关于android - Classcastexception图表引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18154554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com