0

现在我正在尝试使用 achartengine 在 android 中创建条形图。但是当我尝试运行我的应用程序时,它只是提示这样“抱歉您的应用程序意外关闭!..再试一次。强制关闭”

任何人都可以让我清楚这个概念吗?

请找到我的来源和 logcat 以供参考

LOGCAT

08-23 11:22:01.892: D/AndroidRuntime(451): Shutting down VM
08-23 11:22:01.922: W/dalvikvm(451): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-23 11:22:02.002: E/AndroidRuntime(451): FATAL EXCEPTION: main
08-23 11:22:02.002: E/AndroidRuntime(451): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.barchart/com.example.barchart.BarActivity}: java.lang.ClassCastException: com.example.barchart.BarActivity
08-23 11:22:02.002: E/AndroidRuntime(451):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
08-23 11:22:02.002: E/AndroidRuntime(451):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-23 11:22:02.002: E/AndroidRuntime(451):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-23 11:22:02.002: E/AndroidRuntime(451):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-23 11:22:02.002: E/AndroidRuntime(451):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 11:22:02.002: E/AndroidRuntime(451):  at android.os.Looper.loop(Looper.java:123)
08-23 11:22:02.002: E/AndroidRuntime(451):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-23 11:22:02.002: E/AndroidRuntime(451):  at java.lang.reflect.Method.invokeNative(Native Method)
08-23 11:22:02.002: E/AndroidRuntime(451):  at java.lang.reflect.Method.invoke(Method.java:521)
08-23 11:22:02.002: E/AndroidRuntime(451):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-23 11:22:02.002: E/AndroidRuntime(451):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-23 11:22:02.002: E/AndroidRuntime(451):  at dalvik.system.NativeStart.main(Native Method)
08-23 11:22:02.002: E/AndroidRuntime(451): Caused by: java.lang.ClassCastException: com.example.barchart.BarActivity
08-23 11:22:02.002: E/AndroidRuntime(451):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-23 11:22:02.002: E/AndroidRuntime(451):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
08-23 11:22:02.002: E/AndroidRuntime(451):  ... 11 more

BarActivity.java

   public class BarActivity{
   public Intent getIntent(Context context)
   { 
     XYMultipleSeriesRenderer mrenderer = new XYMultipleSeriesRenderer();
     double[] range = {0,5,0,5};

    int[] y = {24,30,12};
    CategorySeries series1 = new CategorySeries("Today");
    CategorySeries series2 = new CategorySeries("Next day");
    CategorySeries series3 = new CategorySeries("2 days later");

    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

 for (int i=0;i<3;i++){
     switch(i){
     case 0:
            series1.add(y[0]);
            dataset.addSeries(series1.toXYSeries());
            break;
     case 1:
            series2.add(y[1]);
            dataset.addSeries(series2.toXYSeries());
            break;
     case 2:
            series3.add(y[2]);
            dataset.addSeries(series3.toXYSeries());
            break;
     }
 }

XYSeriesRenderer renderer1 = new XYSeriesRenderer();
renderer1.setColor(Color.GREEN);
XYSeriesRenderer renderer2 = new XYSeriesRenderer();
renderer2.setColor(Color.BLUE);
XYSeriesRenderer renderer3 = new XYSeriesRenderer();
renderer3.setColor(Color.RED);
    mrenderer.setAxisTitleTextSize(16);
    mrenderer.setChartTitleTextSize(20);
    mrenderer.setLabelsTextSize(15);
    mrenderer.setLegendTextSize(15);
    mrenderer.setBarSpacing(0);
    mrenderer.setXLabels(1);
    mrenderer.addXTextLabel(2.5, "Outstanding jobs");
    mrenderer.setMargins(new int[] {20, 30, 15, 0});
    mrenderer.setAxesColor(Color.WHITE);
    mrenderer.setChartTitle("Work per day");
    mrenderer.setXTitle("Days");
    mrenderer.setInitialRange(range, 1);
    mrenderer.setBarSpacing(1);
    mrenderer.setXAxisMin(0);
    mrenderer.setXAxisMax(5);
    mrenderer.setYAxisMin(0);
    mrenderer.setPanEnabled(false, false);
    mrenderer.setZoomEnabled(false, false);
    mrenderer.addSeriesRenderer(renderer1);
    mrenderer.addSeriesRenderer(renderer2);
    mrenderer.addSeriesRenderer(renderer3);
Intent intent = ChartFactory.getBarChartIntent(context, dataset, mrenderer, Type.DEFAULT);
return intent;  
}
}

主要的.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>

清单.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.barchart"
android:versionCode="1"
android:versionName="1.0" >

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity android:name="org.achartengine.GraphicalActivity" />
    <activity
        android:name=".BarActivity"
        android:label="@string/title_activity_bar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>
4

1 回答 1

2

这不是 AChartEngine 问题。

BarActivity必须扩展Activity该类或其子类之一。

于 2012-08-23T07:14:21.570 回答