2014-05-08 106 views
0

我正在編寫我的第一個圖形應用程序,我在線上學習了一個教程。我正在使用AChartEngine,我有一個主要的活動,它有一個按鈕。當按下按鈕時,它假定繪製傳遞給它的數據,但是當按下按鈕時,應用程序崩潰,我得到一個uncaught thread exception以及Could 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; 
} 


} 

回答

0

我在代碼中看不到按鈕單擊偵聽器。

您是否正在像這樣定義佈局xml文件中的點擊方式example

如果是這樣,你需要一個「做它」的方法!這是它尋找的方法。

相關問題