无法查看图表

时间:2014-06-30 05:28:24

标签: android android-layout android-intent android-activity android-fragments

我创建了一个应用程序,我想查看图表。但是当我点击指定的按钮时,应用程序停止了.. 代码如下..:

BloodSugarChart2.java

package com.example.app;

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

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class BloodSugarChart2 extends Activity 
{
    private String[] mMonth = new String[] {
            "Jan-10-14", "Jan-11-14" , "Jan-12-14", "Jan-13-14", "Jan-14-14", "Jan-15-14",
            "Jan-16-14", "Jan-17-14" , "Jan-18-14", "Jan-19-14", "Jan-20-14", "Jan-21-14"
            };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.blood_sugar_chart2);

          // Getting reference to the button btn_chart
        Button btnChart = (Button) findViewById(R.id.btn_chart);
        // Defining click event listener for the button btn_chart
        OnClickListener clickListener = new OnClickListener() {

            @Override
            public void onClick(View v) {
                // Draw the Income vs Expense Chart
                openChart();                
            }
        };

        // Setting event click listener for the button btn_chart of the MainActivity layout
        btnChart.setOnClickListener(clickListener);

    }

    private void openChart(){
        int[] x = { 0,1,2,3,4,5,6,7 };
        int[] BloodSugar = { 2000,2500,2700,3000,2800,3500,3700,3800};





        // Creating an  XYSeries for Income
        //CategorySeries incomeSeries = new CategorySeries("Income");
        XYSeries BloodSugarSeries = new XYSeries("Blood Sugar");
        // Creating an  XYSeries for Income

        // Adding data to Income and Expense Series
        for(int i=0;i<x.length;i++){            
            BloodSugarSeries.add(i,BloodSugar[i]);

        }


        // Creating a dataset to hold each series
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        // Adding Income Series to the dataset
        dataset.addSeries(BloodSugarSeries);
        // Adding Expense Series to dataset



        // Creating XYSeriesRenderer to customize incomeSeries
        XYSeriesRenderer BloodSugarRenderer = new XYSeriesRenderer();
        BloodSugarRenderer.setColor(Color.GREEN);
        BloodSugarRenderer.setChartValuesSpacing((float) 0.5);

        BloodSugarRenderer.setFillPoints(true);
        BloodSugarRenderer.setLineWidth(2);
        BloodSugarRenderer.setDisplayChartValues(true);



        // Creating a XYMultipleSeriesRenderer to customize the whole chart
        XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
        multiRenderer.setXLabels(0);
         multiRenderer.setBarSpacing(1);
        multiRenderer.setChartTitle("Blood Sugar Progress Analysis Report");
        /*multiRenderer.setXTitle("Year 2012");*/
        multiRenderer.setYTitle("Blood Sugar in mg/dL");
        multiRenderer.setZoomButtonsVisible(true);  

        for(int i=0; i< x.length;i++){
            multiRenderer.addXTextLabel(i, mMonth[i]);          
        }       


        // Adding incomeRenderer and expenseRenderer to multipleRenderer
        // Note: The order of adding dataseries to dataset and renderers to multipleRenderer
        // should be same
        multiRenderer.addSeriesRenderer(BloodSugarRenderer);


        // Creating an intent to plot bar chart using dataset and multipleRenderer      
        Intent intent = ChartFactory.getBarChartIntent(getBaseContext(), dataset, multiRenderer, Type.DEFAULT);

        // Start Activity
        startActivity(intent);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.blood_sugar_chart2, menu);
        return true;
    }
}

blood_sugar_chart2.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/btn_chart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/str_btn_chart"
        tools:context=".MainActivity" />

</RelativeLayout>

Manifestfile.xml

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat" >
        <activity
            android:name="com.example.app.TabBar"
            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.app.Tab1" >
        </activity>
        <activity android:name="com.example.app.Tab2" >
        </activity>
        <activity android:name="com.example.app.Tab3" >
        </activity>
        <activity
            android:name="com.example.app.Person"
            android:label="@string/title_activity_person" >
        </activity>
        <activity
            android:name="com.example.app.History"
            android:label="@string/title_activity_history" >
        </activity>
        <activity
            android:name="com.example.app.Medications"
            android:label="@string/title_activity_medications" >
        </activity>
        <activity
            android:name="com.example.app.AddMedRecords"
            android:label="@string/title_activity_add_med_records" >
        </activity>
        <activity
            android:name="com.example.app.OfficeVisit"
            android:label="@string/title_activity_office_visit" >
        </activity>
        <activity
            android:name="com.example.app.AddOfficeVisit"
            android:label="@string/title_activity_add_office_visit" >
        </activity>
        <activity
            android:name="com.example.app.OfficeInfo"
            android:label="@string/title_activity_office_info" >
        </activity>
        <activity
            android:name="com.example.app.AddOfficeInfo"
            android:label="@string/title_activity_add_office_info" >
        </activity>
        <activity
            android:name="com.example.app.OfficeInfoExtraDetails"
            android:label="@string/title_activity_office_info_extra_details" >
        </activity>
        <activity android:name="com.example.app.AddPerson" >
        </activity>
        <activity
            android:name="com.example.app.RenamePerson"
            android:label="@string/title_activity_rename_person" >
        </activity>
        <activity
            android:name="com.example.app.Weight"
            android:label="@string/title_activity_weight" >
        </activity>
        <activity
            android:name="com.example.app.WeightInfo"
            android:label="@string/title_activity_weight_info" >
        </activity>
        <activity
            android:name="com.example.app.BloodPressure"
            android:label="@string/title_activity_blood_pressure" >
        </activity>
        <activity
            android:name="com.example.app.AddBloodPressureInfo"
            android:label="@string/title_activity_add_blood_pressure_info" >
        </activity>
        <activity
            android:name="com.example.app.BloodSugarCharts"
            android:label="@string/title_activity_blood_sugar_charts" >
        </activity>
        <activity
            android:name="com.example.app.BloodSugar"
            android:label="@string/title_activity_blood_sugar" >
        </activity>
        <activity
            android:name="com.example.app.AddHistory"
            android:label="@string/title_activity_add_history" >
        </activity>
        <activity
            android:name="com.example.app.LabAndTestResults"
            android:label="@string/title_activity_lab_and_test_results" >
        </activity>
        <activity
            android:name="com.example.app.AddLabTestResult"
            android:label="@string/title_activity_add_lab_test_result" >
        </activity>
        <activity android:name="com.example.app.DataAnalysis" >
        </activity>
        <activity
            android:name="com.example.app.Welcome"
            android:label="@string/title_activity_welcome" >
        </activity>
        <activity
            android:name="com.example.app.SimpleListActivity"
            android:label="@string/title_activity_simple_list" >
        </activity>
        <activity
            android:name="com.example.app.WeightCharts"
            android:label="@string/title_activity_weight_charts" >
        </activity>
        <activity
            android:name="com.example.app.BMICharts"
            android:label="@string/title_activity_bmicharts" >
        </activity>
        <activity
            android:name="com.example.app.BloodSugarChart2"
            android:label="@string/title_activity_blood_sugar_chart2" >
        </activity>
    </application>

</manifest>

logcat的

06-30 01:15:43.380: E/AndroidRuntime(795): FATAL EXCEPTION: main
06-30 01:15:43.380: E/AndroidRuntime(795): Process: com.example.app, PID: 795
06-30 01:15:43.380: E/AndroidRuntime(795): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.app/org.achartengine.GraphicalActivity}; have you declared this activity in your AndroidManifest.xml?
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.app.Activity.startActivityForResult(Activity.java:3424)
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.app.Activity.startActivityForResult(Activity.java:3385)
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.app.Activity.startActivity(Activity.java:3627)
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.app.Activity.startActivity(Activity.java:3595)
06-30 01:15:43.380: E/AndroidRuntime(795):  at com.example.app.BloodSugarChart2.openChart(BloodSugarChart2.java:110)
06-30 01:15:43.380: E/AndroidRuntime(795):  at com.example.app.BloodSugarChart2.access$0(BloodSugarChart2.java:47)
06-30 01:15:43.380: E/AndroidRuntime(795):  at com.example.app.BloodSugarChart2$1.onClick(BloodSugarChart2.java:38)
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.view.View.performClick(View.java:4438)
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.view.View$PerformClick.run(View.java:18422)
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.os.Handler.handleCallback(Handler.java:733)
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.os.Handler.dispatchMessage(Handler.java:95)
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.os.Looper.loop(Looper.java:136)
06-30 01:15:43.380: E/AndroidRuntime(795):  at android.app.ActivityThread.main(ActivityThread.java:5017)
06-30 01:15:43.380: E/AndroidRuntime(795):  at java.lang.reflect.Method.invokeNative(Native Method)
06-30 01:15:43.380: E/AndroidRuntime(795):  at java.lang.reflect.Method.invoke(Method.java:515)
06-30 01:15:43.380: E/AndroidRuntime(795):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-30 01:15:43.380: E/AndroidRuntime(795):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-30 01:15:43.380: E/AndroidRuntime(795):  at dalvik.system.NativeStart.main(Native Method)

我已经在ManifestFile中提到了它,然后我也面临着问题..请帮助..

0 个答案:

没有答案