title: AsyncTask Error when Network is not Stable
body: <p>I am still new to Android Development. I wanna ask about AsyncTask.</p>
  
  <p>I am developing an Android Apps using Fragments, AChartEngine, and AsyncTask to parse JSON File from a Server. If connection is stable and runs well, everything is fine. Fragment will parse JSON File according to URL I have selected.</p>
  
  <p>However, I have a problem when connection is not stable. This is how I produce the problem.</p>
  
  <ol>
  <li>I connected to the Access Point.</li>
  <li>I ran the apps. Everything was fine. I changed the landscape from portrait to landscape and vice versa. I moved between fragment. There was no problem.</li>
  <li>Whereas, when I tried to disconnect to AP. The problem started. I moved to another fragment but it did't show the exception I prepared. It showed the previous graph that was successfully created when connection was fine.</li>
  <li>This is the error I am talking.</li>
  <li>I want to load the graph using the URL everytime Fragment started.</li>
  </ol>
  
  <p>This is How I Generate Fragment.</p>
  
  <pre><code>private void displayView(int position) {
      // update the main content by replacing fragments
      Fragment fragment = null;
      switch (position) {
      case 0:
          fragment = new HomeFragment();
          break;
      case 1:
          fragment = new BackboneFragment();
          break;
      case 2:
          fragment = new MinyakFragment();
          break;
      case 3:
          fragment = new GasFragment();
          break;
  
      default:
          break;
      }
  
      if (fragment != null) {
          FragmentManager fragmentManager = getFragmentManager();
          fragmentManager.beginTransaction()
                  .replace(R.id.frame_container, fragment).commit();
  
          // update selected item and title, then close the drawer
          mDrawerList.setItemChecked(position, true);
          mDrawerList.setSelection(position);
          setTitle(navMenuTitles[position]);
          mDrawerLayout.closeDrawer(mDrawerList);
      } else {
          // error in creating fragment
          Log.e("MainActivity", "Error in creating fragment");
      }
  }
  </code></pre>
  
  <p>This is my Fragment Class</p>
  
  <pre><code>public class GasFragment extends Fragment {
  
  //Development URL
  private static String url = "http://192.168.0.100/jsontraining/flash_data_url_gas_die.json";
  
  //Y-Values
  private static ArrayList&lt;HashMap&lt;String, ArrayList&lt;Long&gt;&gt;&gt; jsonlist = new ArrayList&lt;HashMap&lt;String, ArrayList&lt;Long&gt;&gt;&gt;();
  private static HashMap&lt;String, ArrayList&lt;Long&gt;&gt; mapValues = new HashMap&lt;String, ArrayList&lt;Long&gt;&gt;();
  
  //Legends
  private static ArrayList&lt;HashMap&lt;String, String&gt;&gt; jsonListString = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  private static HashMap&lt;String, String&gt; mapValuesText = new HashMap&lt;String,String&gt;();
  
  private static ArrayList&lt;String&gt; dateStringArray = new ArrayList&lt;String&gt;();
  
  private GraphicalView chartView;
  
  public GasFragment(){}
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.fragment_gas, container, false);
      new JSONParse().execute();
      return rootView;
  }
  
  @SuppressWarnings("unchecked")
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
  }
  
  @Override
  public void onResume() {
      super.onResume();
      jsonlist.clear();
      mapValues.clear();
  
  }
  
  private class JSONParse extends AsyncTask&lt;String, String, JSONObject&gt;
  {
      private ProgressDialog pDialog;
      @Override
      protected void onPreExecute() 
      {
          super.onPreExecute();
          pDialog = new ProgressDialog(getActivity());
          pDialog.setMessage("Getting Data ...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(true);
          pDialog.show();
      }//End of onPreExecute
  
      @Override
      protected JSONObject doInBackground(String... args) 
      {
          JSONParser jParser = new JSONParser();
          JSONObject json = jParser.getJSONFromUrl(url);
          return json;
      }//End of doInBackground
  
      @Override
      protected void onPostExecute(JSONObject json) 
      {
          pDialog.dismiss();
          try 
          {
              //Fetching Array of Elements
              JSONArray jsonArray = json.getJSONArray("elements");
  
              //Fetching for TextView
              //Fetching for Pertamina EP
  
              JSONObject jsonYAxis = json.getJSONObject("y_axis");
              Long yAxisMin = jsonYAxis.getLong("min");
              Long yAxisMax = jsonYAxis.getLong("max");
  
              JSONObject jsonYLegend = json.getJSONObject("y_legend");
              String y_legend = jsonYLegend.getString("text");
  
              JSONObject jsonXLegend = json.getJSONObject("x_legend");
              String x_legend = jsonXLegend.getString("text");
  
              TextView uid;
              JSONObject jsonTitle= json.getJSONObject("title");
              String title = jsonTitle.getString("text");
              uid = (TextView) getActivity().findViewById(R.id.txtLabel_gas);
              uid.setText(title);
  
  
              //Fetching for Date
              JSONObject jsonObjectXAxis = json.getJSONObject("x_axis");
              JSONObject jsonObjectXAxisLabels = jsonObjectXAxis.getJSONObject("labels");
              JSONArray jsonArrayXAxisLabels = jsonObjectXAxisLabels.getJSONArray("labels");
              for(int i=0;i&lt;jsonArrayXAxisLabels.length();i++)
              {
                  dateStringArray.add((String) jsonArrayXAxisLabels.getString(i));
              }
  
              for (int i=0;i&lt;jsonArray.length();i++) 
              {
                  ArrayList&lt;Long&gt; list = new ArrayList&lt;Long&gt;();
                  HashMap&lt;String, ArrayList&lt;Long&gt;&gt; mapValues = new HashMap&lt;String, ArrayList&lt;Long&gt;&gt;();
                  HashMap&lt;String, String&gt; mapValuesText = new HashMap&lt;String,String&gt;();
                  JSONObject elementNo = (JSONObject) jsonArray.get(i);
                  JSONArray valuesGraph = (JSONArray) elementNo.get("values");
                  String texts = elementNo.getString("text");
                  String colours = elementNo.getString("colour");
  
                  int len = valuesGraph.length();
                  for (int x=0;x&lt;len;x++)
                  {
                      if(!valuesGraph.isNull(x))
                      {
                          Long nilai = (Long)valuesGraph.getLong(x);
                          list.add(nilai);
                      }
                  }
                  mapValues.put("Values", list); 
                  mapValuesText.put("Text", texts);
                  mapValuesText.put("Colour", colours);
  
                  jsonlist.add(mapValues);
                  jsonListString.add(mapValuesText);
              }
  
              //Line Graph
              XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
  
              XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
  
              mRenderer.setApplyBackgroundColor(true);
              mRenderer.setBackgroundColor(Color.rgb(254, 254, 254));
              mRenderer.setMarginsColor(Color.rgb(254, 254, 254));
  
              int[] x = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
  
              for(int start=0; start&lt;jsonlist.size(); start++)
              {
                  //start++;
                  mapValuesText = jsonListString.get(start);
                  TimeSeries series = new TimeSeries(mapValuesText.get("Text").trim()+"");
                  //start--;
                  mapValues = jsonlist.get(start);
                  int jumlahValues = mapValues.get("Values").size();
  
                  for(int i=0; i&lt;jumlahValues; i++)
                  {
                      series.add(x[i], mapValues.get("Values").get(i));
                  }
                  dataset.addSeries(series);
                  XYSeriesRenderer renderer = new XYSeriesRenderer();
                  renderer.setShowLegendItem(true);
                  renderer.setChartValuesTextSize(24);
                  renderer.setColor(Color.parseColor(mapValuesText.get("Colour").toString()));
                  renderer.setLineWidth(3);
                  renderer.setPointStyle(PointStyle.CIRCLE);
                  renderer.setFillPoints(true);
                  //renderer.setDisplayChartValues(true);
                  mRenderer.addSeriesRenderer(renderer);
  
              }
  
  
  
              //XY Titles
              mRenderer.setYTitle(y_legend);
              //mRenderer.setXTitle(x_legend);
              mRenderer.setChartTitle(x_legend);
              mRenderer.setChartTitleTextSize(30);
              mRenderer.setAxisTitleTextSize(22);
              mRenderer.setLabelsTextSize(22);
              mRenderer.setXLabelsColor(Color.BLACK);
              mRenderer.setYLabelsColor(0, Color.BLACK);
              mRenderer.setShowLabels(true);
              mRenderer.setXLabels(dateStringArray.size());
  
              //Legends
              //Legends
              mRenderer.setShowLegend(true);
              //mRenderer.setFitLegend(true);
              mRenderer.setLegendTextSize(20);
              mRenderer.setXLabelsPadding(20);
  
              mRenderer.setYLabelsAlign(Align.RIGHT, 0);
              mRenderer.setYLabelsPadding(7);
              mRenderer.setYLabelsVerticalPadding(-5);
  
              if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) 
              {
                  for (int i = 0; i &lt; jsonArrayXAxisLabels.length();) 
                  { 
                      String xChartDates = jsonArrayXAxisLabels.getString(i);
                      mRenderer.addTextLabel(i+1, xChartDates);
                      if(mapValues.get("Values").size()&lt;9)
                      {
                          i=i+1;
                      }
                      else
                      {
                          i=i+4;
                      }
                  }
                  mRenderer.setXLabelsAlign(Align.CENTER);
                  mRenderer.setXLabels(0);
              } else {
                  for (int i = 0; i &lt; jsonArrayXAxisLabels.length(); i++) 
                  { 
                      String xChartDates = jsonArrayXAxisLabels.getString(i);
                      mRenderer.addTextLabel(i+1, xChartDates);
                  }
                  mRenderer.setXLabelsAlign(Align.CENTER);
                  mRenderer.setXLabels(0);
              }
  
              mRenderer.setAxesColor(Color.BLACK);
              mRenderer.setLabelsColor(Color.BLACK);
              mRenderer.setMargins(new int[]{ 10, 110, 10, 10});
              mRenderer.setYAxisMax(yAxisMax);
              mRenderer.setYAxisMin(yAxisMin);
  
              mRenderer.setPointSize(9.5f);
              //mRenderer.setPanLimits(new double[]{0, (jsonArrayXAxisLabels.length())*1.1, yAxisMin, yAxisMax});
              mRenderer.setInScroll(true);
              mRenderer.setClickEnabled(true);
  
              //Grid
              mRenderer.setShowGrid(true);
              //mRenderer.setShowGridX(true);
              //mRenderer.setShowGridY(true);
              mRenderer.setShowCustomTextGrid(true);
              mRenderer.setGridColor(Color.rgb(162,172,186));
  
  
  
              if(chartView!=null)
              {
                  chartView.repaint();
              }
              else{
                  chartView = ChartFactory.getLineChartView(getActivity(), dataset, mRenderer);
                  //chartView.repaint();
  
                  //layout.addView(chartView, new LayoutParams(960,LayoutParams.FILL_PARENT));
  
              }
  
              chartView.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    SeriesSelection seriesSelection = chartView.getCurrentSeriesAndPoint();
                    double[] xy = chartView.toRealPoint(0);
  
                    if (seriesSelection == null) 
                    {
                      //Toast.makeText(getActivity(), "No chart element was clicked", Toast.LENGTH_SHORT).show();
                    } else {
  
                        Long values = (long) seriesSelection.getValue();
                          mapValuesText = jsonListString.get(seriesSelection.getSeriesIndex());
                          int xValue = (int)seriesSelection.getXValue()-1;
  
                          Toast.makeText(getActivity(), ""+mapValuesText.get("Text").trim()+". \n"+NumberFormat.getNumberInstance(Locale.GERMAN).format(values)
                                  +" BBLs pada Hari ke-"+dateStringArray.get(xValue)+""
                                  , Toast.LENGTH_LONG).show();
  
                    }
                  }
                }); 
  
  
  
              LinearLayout layout = (LinearLayout) getActivity().findViewById(R.id.dashboard_chart_layout_gas);
              layout.removeAllViews();
              layout.addView(chartView);
  
          } catch (JSONException e) 
          {
           e.printStackTrace();
          }
      }//End of doInBackground
  
  }}
  </code></pre>
  
  <p>Here is Another Fragment Class</p>
  
  <pre><code>public class HomeFragment extends Fragment {
  
  //Development URL
  private static String url = "http://192.168.0.100/jsontraining/production.json";
  
  //Y-Values
  private static ArrayList&lt;HashMap&lt;String, ArrayList&lt;Long&gt;&gt;&gt; jsonlist = new ArrayList&lt;HashMap&lt;String, ArrayList&lt;Long&gt;&gt;&gt;();
  private static HashMap&lt;String, ArrayList&lt;Long&gt;&gt; mapValues = new HashMap&lt;String, ArrayList&lt;Long&gt;&gt;();
  
  //Legends
  private static ArrayList&lt;HashMap&lt;String, String&gt;&gt; jsonListString = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  private static HashMap&lt;String, String&gt; mapValuesText = new HashMap&lt;String,String&gt;();
  
  private static ArrayList&lt;String&gt; dateStringArray = new ArrayList&lt;String&gt;();
  
  private GraphicalView chartView;
  
  private XYMultipleSeriesRenderer mRenderer;
  
  public HomeFragment(){}
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_home, container, false);
      //setRetainInstance(true);
      new JSONParse().execute();
      return rootView;
  }
  
  @SuppressWarnings("unchecked")
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
  }
  
  @Override
  public void onResume() 
  {
      super.onResume();
      jsonlist.clear();
      mapValues.clear();
      jsonListString.clear();
      mapValuesText.clear();
  }
  
  private class JSONParse extends AsyncTask&lt;String, String, JSONObject&gt;
  {
      private ProgressDialog pDialog;
  
      @Override
      protected void onPreExecute() 
      {
          super.onPreExecute();
          pDialog = new ProgressDialog(getActivity());
          pDialog.setMessage("Getting Data ...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(true);
          pDialog.show();
      }//End of onPreExecute
  
      @Override
      protected JSONObject doInBackground(String... args) 
      {
          while(!isCancelled())
          {
              JSONParser jParser = new JSONParser();
              JSONObject json = jParser.getJSONFromUrl(url);
              return json;
          }
          return null;            
      }//End of doInBackground
  
      @Override
      protected void onCancelled(JSONObject json) {
          Toast.makeText(getActivity(), "Cancelled. Cannot retrieve data at this time. Please try again later.", Toast.LENGTH_SHORT).show();
      }
  
      @Override
      protected void onPostExecute(JSONObject json) 
      {
          pDialog.dismiss();
          try 
          {
              //Fetching Array of Elements
              JSONArray jsonArray = json.getJSONArray("elements");
  
              //Fetching for TextView
              //Fetching for Pertamina EP
              TextView uid;
              uid = (TextView) getActivity().findViewById(R.id.txtLabel);
              JSONObject jsonElementsText = jsonArray.getJSONObject(jsonArray.length()-1);
              String text = jsonElementsText.getString("text");
              //Fetching for Date
              JSONObject jsonObjectXAxis = json.getJSONObject("x_axis");
              JSONObject jsonObjectXAxisLabels = jsonObjectXAxis.getJSONObject("labels");
              JSONArray jsonArrayXAxisLabels = jsonObjectXAxisLabels.getJSONArray("labels");
              for(int i=0;i&lt;jsonArrayXAxisLabels.length();i++)
              {
                  dateStringArray.add((String) jsonArrayXAxisLabels.getString(i));
              }
              String jsonArrayStringXAxisLabels = (String) jsonArrayXAxisLabels.getString(jsonArrayXAxisLabels.length()-1);
              //JSON String to Date Format
              char[] dateChar = jsonArrayStringXAxisLabels.toCharArray();
              String day = ""+dateChar[0]+""+dateChar[1]+"";
              String monthNo = ""+dateChar[3]+""+dateChar[4]+"";
              if(monthNo.matches("01"))
              {
                  monthNo="January";
              }
              if(monthNo.matches("01"))
              {
                  monthNo="January";
              }
              if(monthNo.matches("02"))
              {
                  monthNo="February";
              }
              if(monthNo.matches("03"))
              {
                  monthNo="March";
              }
              if(monthNo.matches("04"))
              {
                  monthNo="April";
              }
              if(monthNo.matches("05"))
              {
                  monthNo="May";
              }
              if(monthNo.matches("06"))
              {
                  monthNo="June";
              }
              if(monthNo.matches("07"))
              {
                  monthNo="July";
              }
              if(monthNo.matches("08"))
              {
                  monthNo="August";
              }
              if(monthNo.matches("09"))
              {
                  monthNo="September";
              }
              if(monthNo.matches("10"))
              {
                  monthNo="October";
              }
              if(monthNo.matches("11"))
              {
                  monthNo="November";
              }
              if(monthNo.matches("12"))
              {
                  monthNo="December";
              }
              Time today = new Time(Time.getCurrentTimezone());
              today.setToNow();
              int year = today.year;
              //Fetching for Number
              JSONArray jsonArrayValues = jsonElementsText.getJSONArray("values");
              Long arrayValuesMax = jsonArrayValues.getLong(jsonArrayValues.length()-1);
  
              //Fetching to Text View
              //uid.setText("Total produksi minyak "+text+", "+day+" "+monthNo+" "+year+" = "+arrayValuesMax+" BBLs");
              uid.setText(Html.fromHtml("Total produksi minyak &lt;b&gt;"+text+"&lt;/b&gt;, "+day+" "+monthNo+" "+year+" = &lt;b&gt;"+NumberFormat.getNumberInstance(Locale.GERMAN).format(arrayValuesMax)+"&lt;/b&gt; BBLs"));
              JSONObject jsonYAxis = json.getJSONObject("y_axis");
              Long yAxisMin = jsonYAxis.getLong("min");
              Long yAxisMax = jsonYAxis.getLong("max");
  
              for (int i=0;i&lt;jsonArray.length();i++) 
              {
                  ArrayList&lt;Long&gt; list = new ArrayList&lt;Long&gt;();
                  HashMap&lt;String, ArrayList&lt;Long&gt;&gt; mapValues = new HashMap&lt;String, ArrayList&lt;Long&gt;&gt;();
                  JSONObject elementNo = (JSONObject) jsonArray.get(i);
                  JSONArray valuesGraph = (JSONArray) elementNo.get("values");
                  String texts = elementNo.getString("text");
  
                  int len = valuesGraph.length();
                  for (int x=0;x&lt;len;x++)
                  {
                      if(!valuesGraph.isNull(x))
                      {
                          Long nilai = (Long)valuesGraph.getLong(x);
                          list.add(nilai);
                      }
                  }
                  mapValues.put("Values", list); 
                  mapValuesText.put("Text", texts);
  
                  jsonlist.add(mapValues);
                  jsonListString.add(mapValuesText);
              }
  
              //Line Graph
              XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
  
              mRenderer = new XYMultipleSeriesRenderer();
  
              mRenderer.setApplyBackgroundColor(true);
              mRenderer.setBackgroundColor(Color.rgb(254, 254, 254));
              mRenderer.setMarginsColor(Color.rgb(254, 254, 254));
  
              int[] x = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
  
              for(int start=0; start&lt;jsonlist.size(); start++)
              {
                  start++;
                  mapValuesText = jsonListString.get(start-1);
                  TimeSeries series = new TimeSeries(mapValuesText.get("Text").trim());
                  start--;
                  mapValues = jsonlist.get(start);
                  int jumlahValues = mapValues.get("Values").size();
  
                  for(int i=0; i&lt;jumlahValues; i++)
                  {
                      series.add(x[i], mapValues.get("Values").get(i));
                  }
                  dataset.addSeries(series);
                  XYSeriesRenderer renderer = new XYSeriesRenderer();
                  renderer.setShowLegendItem(true);
                  renderer.setChartValuesTextSize(24);
                  renderer.setColor(Color.rgb(0,108,183));
                  renderer.setLineWidth(3);
                  renderer.setPointStyle(PointStyle.CIRCLE);
                  renderer.setFillPoints(true);
                  //renderer.setDisplayChartValues(true);
                  mRenderer.addSeriesRenderer(renderer);
              }
  
              //XY Titles
              mRenderer.setYTitle("Production");
              //mRenderer.setXTitle("Date");
              mRenderer.setAxisTitleTextSize(22);
              mRenderer.setLabelsTextSize(22);
              mRenderer.setXLabelsColor(Color.BLACK);
              mRenderer.setYLabelsColor(0, Color.BLACK);
              mRenderer.setShowLabels(true);
  
              //Legends
              mRenderer.setShowLegend(true);
              //mRenderer.setFitLegend(true);
              mRenderer.setLegendTextSize(20);
              mRenderer.setXLabelsPadding(20);
  
              mRenderer.setYLabelsAlign(Align.RIGHT, 0);
              mRenderer.setYLabelsPadding(7);
              mRenderer.setYLabelsVerticalPadding(-5);
  
              if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) 
              {
                  for (int i = 0; i &lt; jsonArrayXAxisLabels.length();) 
                  { 
                      String xChartDates = jsonArrayXAxisLabels.getString(i);
                      mRenderer.addTextLabel(i+1, xChartDates);
                      if(mapValues.get("Values").size()&lt;9)
                      {
                          i=i+1;
                      }
                      else
                      {
                          i=i+4;
                      }
                  }
                  mRenderer.setXLabelsAlign(Align.CENTER);
                  mRenderer.setXLabels(0);
              } else {
                  for (int i = 0; i &lt; jsonArrayXAxisLabels.length(); i++) 
                  { 
                      String xChartDates = jsonArrayXAxisLabels.getString(i);
                      mRenderer.addTextLabel(i+1, xChartDates);
                  }
                  mRenderer.setXLabelsAlign(Align.CENTER);
                  mRenderer.setXLabels(0);
              }
  
              mRenderer.setAxesColor(Color.BLACK);
              mRenderer.setLabelsColor(Color.BLACK);
              mRenderer.setMargins(new int[]{ 10, 110, 10, 10});
              mRenderer.setYAxisMax(yAxisMax);
              mRenderer.setYAxisMin(yAxisMin);
              mRenderer.setXAxisMin(0);
              mRenderer.setXAxisMax(jsonArrayXAxisLabels.length());
              mRenderer.setPointSize(9.5f);
              //mRenderer.setPanLimits(new double[]{0, (jsonArrayXAxisLabels.length())*1.1, yAxisMin, yAxisMax});
              mRenderer.setInScroll(true);
              mRenderer.setClickEnabled(true);
              mRenderer.setPanEnabled(true);
              mRenderer.setZoomEnabled(true);
              mRenderer.setZoomLimits(new double[]{0, (jsonArrayXAxisLabels.length())*1.1, yAxisMin, yAxisMax});
  
              //Grid
              mRenderer.setShowGrid(true);
              mRenderer.setShowCustomTextGrid(true);
              mRenderer.setGridColor(Color.rgb(162,172,186));
  
              if(chartView!=null)
              {
                  chartView.repaint();
              }
              else{
                  chartView = ChartFactory.getLineChartView(getActivity(), dataset, mRenderer);
              }
  
              chartView.addZoomListener(new ZoomListener() {
  
                  @Override
                  public void zoomReset() {
                      // TODO Auto-generated method stub
  
                  }
  
  
                  @Override
                  public void zoomApplied(ZoomEvent arg0) {
                      // TODO Auto-generated method stub
  
                  }
              }, true, true);
  
              chartView.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    SeriesSelection seriesSelection = chartView.getCurrentSeriesAndPoint();
  
                    if (seriesSelection == null) 
                    {
  
                        chartView.repaint();
  
                    } else {
                      Long values = (long) seriesSelection.getValue();
                      mapValuesText = jsonListString.get(seriesSelection.getSeriesIndex());
                      int xValue = (int)seriesSelection.getXValue()-1;
  
                      Toast.makeText(getActivity(), "Total produksi minyak "+mapValuesText.get("Text")+", "+dateStringArray.get(xValue)+" = "
                              +NumberFormat.getNumberInstance(Locale.GERMAN).format(values)
                              +" BBLs", Toast.LENGTH_LONG).show();
                    }
                  }
                }); 
  
              LinearLayout layout = (LinearLayout) getActivity().findViewById(R.id.dashboard_chart_layout);
              layout.removeAllViews();
              layout.addView(chartView);
  
              TextView failedText;
              failedText = (TextView) getActivity().findViewById(R.id.txtFailedLabel_home);
              failedText.setVisibility(View.GONE);
  
          } catch (JSONException e) 
          {
           e.printStackTrace();
           Toast.makeText(getActivity(), "JSONException. Cannot retrieve data at this time. Please try again later.", Toast.LENGTH_SHORT).show();
  
           TextView failedText;
           failedText = (TextView) getActivity().findViewById(R.id.txtFailedLabel_home);
           failedText.setText("Please Retry");
          }
          catch(Exception e){
              e.printStackTrace();
              Toast.makeText(getActivity(), "Exception. Cannot retrieve data at this time. Please try again later.", Toast.LENGTH_SHORT).show();
  
              TextView failedText;
              failedText = (TextView) getActivity().findViewById(R.id.txtFailedLabel_home);
              failedText.setText("Please Retry");
          }
  
      }//End of doInBackground
  
  }}
  </code></pre>