I was trying to make a graph based on the two array values, i.e conc and optical density. I have created two activities for saving those arrays and pass the array list using bundle and intent to the third activity using string. Whenever I try to run the code, my app crashes.
GraphView gpView;
String co;
String od;
Float x,y;
int l1,l2;
DataPoint [] dp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Bundle bundle1 = getIntent().getExtras();
ArrayList<String> array1 = (ArrayList<String>) bundle1.getStringArrayList("Conc");
Bundle bundle2 = getIntent().getExtras();
ArrayList<String> array2 = (ArrayList<String>) bundle2.getStringArrayList("Od");
gpView= findViewById(R.id.graph);
LineGraphSeries <DataPoint> series = new LineGraphSeries<>();
l1 = array1.size();
l2 = array2.size();
if((array1.contains(true))&&(array2.contains(true)))
{
for (int c1 = 0; c1<l1; c1++)
{
for(int c2=0; c2<l2; c2++ ) {
co = array1.get(c1);
od = array2.get(c2);
x = Float.parseFloat(co);
y = Float.parseFloat(od);
dp[c1] = new DataPoint(x,y);
}
}
gpView.addSeries(series);
}
}
Alternately I tried to run a simple input method and it worked using this
private DataPoint[] getDataPoint ()
{
dp = new DataPoint[]
{
new DataPoint(10, 0.2),
new DataPoint(20, 0.38),
new DataPoint(30, 0.45),
new DataPoint(40, 0.69),
new DataPoint(50, 0.81),
};
return (dp);
}