无法执行活动的方法

时间:2014-05-08 02:05:41

标签: android android-activity uncaught-exception

我正在编写我的第一个图形应用程序,我正在线上学习。我正在使用AChartEngine,我有一个主要活动,上面有一个按钮。当按下按钮时,它会假设图形传递给它,但是当按下按钮时,应用程序崩溃,我得到uncaught thread exceptionCould not execute main activity。我的应用程序崩溃是因为我需要一个单独的活动来完全显示图表吗?我想我可以在按下按钮后重置主屏幕以显示图形。谢谢您的帮助!

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)

这是我的主要活动

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");
}

}

这是我的活动,将数据传递到要绘制的主要活动中。

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;
}


}

1 个答案:

答案 0 :(得分:0)

我的代码中没有看到按钮单击侦听器。

您是否以与此example相同的方式在布局xml文件中定义on click方法?

如果是这样,你需要一个“做它”的方法!这就是它寻找的方法。