I have a program which makes some calculations according to user data. The program works fine ,but when i try to use achartengine in order to make the plot ,it crashes.(doesn't do the plot)
I am not sure if i am passing right the data in the LineGraph class.
As i understand i must use
"Bundle sth=getIntent.getExtras()" but i am not sure where to put it in LineGraph.
I have the number_cores class which in which the user enters the data and then presses the calculate button and in another activity shows the result. In this , i have :
public void cores_func(){
double initcores=Double.parseDouble(num_cores.getText().toString().trim());
double half_time=Double.parseDouble(halftimecores.getText().toString().trim());
double ttime=Double.parseDouble(timecores.getText().toString().trim());
double l=Math.log(2)/half_time;
double fcores=initcores*Math.exp(-l*ttime);
Intent i=new Intent(this,core_calcs.class);
i.putExtra("value",fcores);
i.putExtra("value2",initcores);
startActivity(i);
}
Then , in the core_calcs class (as you can see from the intent above) , i show the result and also i added a button which when the user clicks it ,shows the graph (right now ,it crashes here).
I have (core_calcs) in the onCreate method :
double fcores=getIntent().getExtras().getDouble("value");
double initcores=getIntent().getExtras().getDouble("value2");
and then :
public void onClick(View v) {
switch (v.getId()){
case R.id.show_cores_graph:
double fcores=getIntent().getExtras().getDouble("value");
double initcores=getIntent().getExtras().getDouble("value2");
Intent i = new Intent();
i.setClassName("com.wordpress.androiddevgeo.Radiation",LineGraph.class.getName());
i.putExtra("value", fcores);
i.putExtra("value2", initcores);
this.startActivity(i);
break;
}
}
(also, i have the public void LineGraphHandler (View view) here)
Finally , in the LineGraph class (the intent above):
public class LineGraph extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Bundle extras=getIntent().getExtras();
String fcores=extras.getString("value");
String initcores=extras.getString("value2");
}
public Intent getIntent(Context context){
//double ttime=getIntent(context).getExtras().getDouble("value");
double [] x = {0,100}; //time axis
double [] y = {initcores,fcores}; //number of cores axis
TimeSeries series = new TimeSeries("Number of cores");
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);
Intent intent=ChartFactory.getLineChartIntent(context, dataset, mRenderer,"Decay");
return intent;
}
}
How to pass the data (initcores and fcores ) to the LineGraph?
--------Error messages ---------------------------------------------
W/dalvikvm(734): threadid=3: thread exiting with uncaught exception
(group=0x4000fe70) 01-15 18:42:01.334: E/AndroidRuntime(734): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(734): android.content.ActivityNotFoundException: Unable to find explicit activity class
have you declared this activity in your AndroidManifest.xml?
(I have declared the activity for the LineGraph and also "org.achartengine.GraphicalActivity") Thanks!
Bundle approach:
and in your LineGraph activity:
SharedPreferences approach:
and in your next activity
hope this helps abit