Gerando gráfico usando dados remotos do banco de dados no achartengine
Eu estou tentando gerar um gráfico usando um localizador que puxa os dados de um banco de dados e preenche o gráfico usando os dados. A seguir está o código que preenche o gráfico. Todos os dados são armazenados em
"dataArraylist". Este código preenche os dados no gráfico
<code> CategorySeries series = new CategorySeries("Bar Graph"); //"series" = graph for(int i=0; i< size; i++) { series.add("Bar"+(i+1), dataArraylist.get(i)); //add each of the value to the series i.e graph } XYMultipleSeriesDataset dataset= new XYMultipleSeriesDataset(); dataset.addSeries(series.toXYSeries()); //add the graph into a dataset // customisation for the first line XYSeriesRenderer renderer = new XYSeriesRenderer(); renderer.setDisplayChartValues(true); renderer.setChartValuesSpacing((float) 0.5); renderer.setColor(Color.WHITE); XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); //create a new renderer. mRenderer.addSeriesRenderer(renderer); //renderer lets one to change the proerties of the graph i.e line colour etc mRenderer.setXTitle("X VALUES"); mRenderer.setXTitle("Y VALUES"); mRenderer.setChartTitle("This is title"); Intent intent = ChartFactory.getBarChartIntent(context, dataset, mRenderer,Type.DEFAULT, "Title"); //package the whole chart together return intent; </code>
no entanto, quando tento compilá-lo, recebo o erro Null Exception, a seguir está o erro recebido após a exceção nula:
<code> 04-07 21:09:31.713: E/AndroidRuntime(4091): java.lang.IllegalStateException: Could not execute method of the activity </code>
Eu também estou tendo problemas em passar os dados de uma atividade para a atividade gráfica. Uma resposta seria apreciada
Log completo é:
<code> 04-07 21:09:31.674: D/AndroidRuntime(4091): Shutting down VM 04-07 21:09:31.674: W/dalvikvm(4091): threadid=1: thread exiting with uncaught exception (group=0x40015560) 04-07 21:09:31.713: E/AndroidRuntime(4091): FATAL EXCEPTION: main 04-07 21:09:31.713: E/AndroidRuntime(4091): java.lang.IllegalStateException: Could not execute method of the activity 04-07 21:09:31.713: E/AndroidRuntime(4091): at android.view.View$1.onClick(View.java:2144) 04-07 21:09:31.713: E/AndroidRuntime(4091): at android.view.View.performClick(View.java:2485) 04-07 21:09:31.713: E/AndroidRuntime(4091): at android.view.View$PerformClick.run(View.java:9080) 04-07 21:09:31.713: E/AndroidRuntime(4091): at android.os.Handler.handleCallback(Handler.java:587) 04-07 21:09:31.713: E/AndroidRuntime(4091): at android.os.Handler.dispatchMessage(Handler.java:92) 04-07 21:09:31.713: E/AndroidRuntime(4091): at android.os.Looper.loop(Looper.java:123) 04-07 21:09:31.713: E/AndroidRuntime(4091): at android.app.ActivityThread.main(ActivityThread.java:3683) 04-07 21:09:31.713: E/AndroidRuntime(4091): at java.lang.reflect.Method.invokeNative(Native Method) 04-07 21:09:31.713: E/AndroidRuntime(4091): at java.lang.reflect.Method.invoke(Method.java:507) 04-07 21:09:31.713: E/AndroidRuntime(4091): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 04-07 21:09:31.713: E/AndroidRuntime(4091): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 04-07 21:09:31.713: E/AndroidRuntime(4091): at dalvik.system.NativeStart.main(Native Method) 04-07 21:09:31.713: E/AndroidRuntime(4091): Caused by: java.lang.reflect.InvocationTargetException 04-07 21:09:31.713: E/AndroidRuntime(4091): at java.lang.reflect.Method.invokeNative(Native Method) 04-07 21:09:31.713: E/AndroidRuntime(4091): at java.lang.reflect.Method.invoke(Method.java:507) 04-07 21:09:31.713: E/AndroidRuntime(4091): at android.view.View$1.onClick(View.java:2139) 04-07 21:09:31.713: E/AndroidRuntime(4091): ... 11 more 04-07 21:09:31.713: E/AndroidRuntime(4091): Caused by: java.lang.NullPointerException 04-07 21:09:31.713: E/AndroidRuntime(4091): at hudds.fc.coach.ReadinessGraph.getIntent(ReadinessGraph.java:45) 04-07 21:09:31.713: E/AndroidRuntime(4091): at hudds.fc.coach.Overview.generateGraph(Overview.java:101) 04-07 21:09:31.713: E/AndroidRuntime(4091): ... 14 more 04-07 21:09:34.746: I/Process(4091): Sending signal. PID: 4091 SIG: 9 </code>
O código a seguir faz o download dos dados do banco de dados:
<code> try { if (json.getString(KEY_SUCCESS) != null) { String getsize=json.getString("size"); size = Integer.parseInt(getsize); for (int i = 0; i < size; i++) { String getRating=json.getJSONArray("number").getJSONObject(i).getString("rating_number"); int rating = Integer.parseInt(getRating); readinessRatng.add(rating); String printratings=readinessRatng.toString(); Log.e("ratings are", printratings); } } else{ } } catch (JSONException e) { e.printStackTrace(); } </code>