Question

I'm trying to use the aChart engine library for an android app. this is the activity i'm trying to run with an onClick event.

package com.example.euroxxi_testeficheiro;


import org.achartengine.ChartFactory;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.model.CategorySeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

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

public class ChartTeste extends Activity{

    public Intent getIntent(Context context) 
    {   
        // Bar 1
        int[] y = { 124, 135, 443, 456, 234, 123, 342, 134, 123, 643, 234, 274 };
        CategorySeries series = new CategorySeries("Demo Bar Graph 1");
        for (int i = 0; i < y.length; i++) {
            series.add("Bar " + (i+1), y[i]);
        }

        // Bar 2
        int[] y2 = { 224, 235, 243, 256, 234, 223, 242, 234, 223, 243, 234, 274 };
        CategorySeries series2 = new CategorySeries("Demo Bar Graph 2");
        for (int i = 0; i < y.length; i++) {
            series2.add("Bar " + (i+1), y2[i]);
        }

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        dataset.addSeries(series.toXYSeries());
        dataset.addSeries(series2.toXYSeries());

        // This is how the "Graph" itself will look like
        XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
        mRenderer.setChartTitle("Demo Graph Title");
        mRenderer.setXTitle("X VALUES");
        mRenderer.setYTitle("Y VALUES");
        mRenderer.setAxesColor(Color.GREEN);
        mRenderer.setLabelsColor(Color.RED);
        // Customize bar 1
        XYSeriesRenderer renderer = new XYSeriesRenderer();
        renderer.setDisplayChartValues(true);
        renderer.setChartValuesSpacing((float) 0.5);
        mRenderer.addSeriesRenderer(renderer);
        // Customize bar 2
        XYSeriesRenderer renderer2 = new XYSeriesRenderer();
        renderer.setColor(Color.CYAN);
        renderer.setDisplayChartValues(true);
        renderer.setChartValuesSpacing((float) 0.5);
        mRenderer.addSeriesRenderer(renderer2);

        Intent intent = ChartFactory.getBarChartIntent(context, dataset,mRenderer, Type.DEFAULT);
        return intent;
    }

}

XML layout

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/chart"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".ChartTeste" >

</LinearLayout>

AndroidManifest.xml

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.euroxxi_testeficheiro.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="com.example.euroxxi_testeficheiro.ConsultaClientesActivity"
            android:label="@string/title_activity_consulta_clientes" >
        </activity>
        <activity
            android:name="com.example.euroxxi_testeficheiro.ConsultaCondutoresActivity"
            android:label="@string/title_activity_consulta_clientes" >
        </activity>
        <activity
            android:name="com.example.euroxxi_testeficheiro.ConsultaFornecedoresActivity"
            android:label="@string/title_activity_consultar_fornecedores" >
        </activity>
        <activity
            android:name="com.example.euroxxi_testeficheiro.TesteGrafico"
            android:label="@string/title_activity_teste_grafico" >
        </activity>
        <activity
            android:name="com.example.euroxxi_testeficheiro.ChartTeste"
            android:label="@string/title_activity_chart_teste" >
        </activity>
    </application>

</manifest>

I have declared this activity in the AndroidManifest but i keep getting the same error log.

05-14 12:27:01.973: E/AndroidRuntime(5256): FATAL EXCEPTION: main
05-14 12:27:01.973: E/AndroidRuntime(5256): Process: com.example.euroxxi_testeficheiro, PID: 5256
05-14 12:27:01.973: E/AndroidRuntime(5256): java.lang.IllegalStateException: Could not execute method of the activity
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.view.View$1.onClick(View.java:3969)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.view.View.performClick(View.java:4633)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.view.View$PerformClick.run(View.java:19330)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.os.Handler.handleCallback(Handler.java:733)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.os.Handler.dispatchMessage(Handler.java:95)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.os.Looper.loop(Looper.java:157)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.app.ActivityThread.main(ActivityThread.java:5356)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at java.lang.reflect.Method.invokeNative(Native Method)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at java.lang.reflect.Method.invoke(Method.java:515)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at dalvik.system.NativeStart.main(Native Method)
05-14 12:27:01.973: E/AndroidRuntime(5256): Caused by: java.lang.reflect.InvocationTargetException
05-14 12:27:01.973: E/AndroidRuntime(5256):     at java.lang.reflect.Method.invokeNative(Native Method)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at java.lang.reflect.Method.invoke(Method.java:515)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.view.View$1.onClick(View.java:3964)
05-14 12:27:01.973: E/AndroidRuntime(5256):     ... 11 more
05-14 12:27:01.973: E/AndroidRuntime(5256): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.euroxxi_testeficheiro/org.achartengine.GraphicalActivity}; have you declared this activity in your AndroidManifest.xml?
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1648)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1442)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.app.Activity.startActivityForResult(Activity.java:3511)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.app.Activity.startActivityForResult(Activity.java:3472)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.app.Activity.startActivity(Activity.java:3714)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at android.app.Activity.startActivity(Activity.java:3682)
05-14 12:27:01.973: E/AndroidRuntime(5256):     at com.example.euroxxi_testeficheiro.MainActivity.ChartPlot(MainActivity.java:79)
05-14 12:27:01.973: E/AndroidRuntime(5256):     ... 14 more

Any help would be appreciated :) if you need more details let me know.

Was it helpful?

Solution

add the below in you manifest file under Application tag.

<activity android:name="org.achartengine.GraphicalActivity">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top