0

I am writing my first graph app and I was following a tutorial online. I am using AChartEngine, and i have a main activity that has a button on it. When the button is pushed it is suppose to graph data that is passed to it, however when the button is pushed the app crashes and I get an uncaught thread exception along with Could not execute main activity. Is my app crashing because I need a separate activity completely to display the graph? I thought I could just reset the main screen to show the graph after I push the button.

05-07 18:44:10.720: W/dalvikvm(9057): threadid=1: thread exiting with uncaught exception (group=0x417bb898)
05-07 18:44:10.730: E/AndroidRuntime(9057): FATAL EXCEPTION: main
05-07 18:44:10.730: E/AndroidRuntime(9057): java.lang.IllegalStateException: Could not execute method of the activity
05-07 18:44:10.730: E/AndroidRuntime(9057):     at android.view.View$1.onClick(View.java:3852)
05-07 18:44:10.730: E/AndroidRuntime(9057):     at android.view.View.performClick(View.java:4489)

Here is my main activity

package com.OhYea.graphthis;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


}

public void LineGraphHandler (View view)
{
    LineGraph line = new LineGraph();
    Log.i("newgraph", "Line Graph");
    Intent lineIntent = line.getIntent(this);
    Log.i("get intent", "get intent");
    startActivity(lineIntent);
    Log.i("start activity", "activity started");
}

}

Here is my activity that passes data into the main activity to be graphed.

package com.OhYea.graphthis;

import org.achartengine.ChartFactory;
import org.achartengine.model.TimeSeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class LineGraph {

public Intent getIntent(Context context)
{
    int[] x ={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int[] y ={30,34,45,57,77,89,100,111,123,145};

    TimeSeries series = new TimeSeries  ("Line1");
    for( int i =0; i< x.length; i++)
    {
        series.add(x[i] , y[i]);
    }

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

    XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
    XYSeriesRenderer renderer = new XYSeriesRenderer();
    mRenderer.addSeriesRenderer(renderer);


    Log.i("passing graph data", "Pass data to graph");
    Intent intent = ChartFactory.getLineChartIntent(context, dataset, mRenderer, "Title");


    return intent;
}


}
Cœur
  • 37,241
  • 25
  • 195
  • 267
wannabe
  • 3
  • 2

1 Answers1

0

I don't see a button click listener in your code.

Are you defining the on click method in the layout xml file in the same way as this example?

If so, you'll need a "Do it" method! And that is the method its looking for.

Community
  • 1
  • 1
Garret
  • 1,137
  • 9
  • 17