I am not sure if I am missing something conceptually or if there is an error in one of my methods, but I have debugged this activity for quite some time and I must be overlooking something huge. At the end of my onCreate, I instantiate an ASyncTask to populate an ArrayList of data from a GET, and then in the onPostExecute I reset the GraphView data with the new data. My onCreate is below:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cholestoral);
graph = (GraphView) findViewById(R.id.graph);
//dummy data for now, TODO: adjust dates to fit in graphical format
HDL_series = new LineGraphSeries<>(new DataPoint[] {
new DataPoint(0, 2),
new DataPoint(1, 1),
new DataPoint(2, 5),
new DataPoint(3, 3),
new DataPoint(4, 6),
});
HDL_series.setColor(Color.RED);
HDL_series.setTitle("HDL");
LDL_series = new LineGraphSeries<>(new DataPoint[] {
new DataPoint(0, 7),
new DataPoint(1, 8),
new DataPoint(2, 5),
new DataPoint(3, 8),
new DataPoint(4, 7),
});
LDL_series.setColor(Color.CYAN);
LDL_series.setTitle("LDL");
graph.addSeries(HDL_series);
graph.addSeries(LDL_series);
//empty arraylist on page load... to be filled in ASyncTask below
new ListCholestoralAPI().execute("http://m-health.cse.nd.edu:8000/phrService-0.0.1-SNAPSHOT/chol/chol/");
The doInBackground correctly populates my list of information, and it gets sent to the onPostExecute which must be the section that keeps crashing the application. My onPostExecute simply calls a function in my activity called initializeGraph().
public void initializeGraph() {
//TODO: initialize graph by setting labels, axes, etc...
HDL_series.resetData(generateDataPoints());
}
public DataPoint[] generateDataPoints() {
dataPointArray = null;
dataPointArray = new DataPoint[30];
for (int i = 0; i < cholesterolInformationList.size(); i++) {
double hdl = cholesterolInformationList.get(i).getHdl();
dataPointArray[i] = new DataPoint(i, hdl);
}
//dataPointArray = sortDataPointArray(dataPointArray);
return dataPointArray;
}
Note: If anything jumps out at you as conceptually flawed here, please let me know! I have spent enormous amounts of time on a fairly simple task.