title: How to update second record after updating the first record in an ArrayList
body: <p>In my Android Application i have <code>Two Activities</code>, in my first <code>Activity</code> is contains List of tickets with TicketId and <code>Update button</code> Here When Click i the update button then it will will go to <code>Activity2</code> and there is text field to update data and button for submit. when i click that button the data was updated and again it come back to <code>Activity1</code>.
     Here is my main problem When i click update button of anther record my App closing with unfortunatly stopped Error below is my code.</p>
  
  <p><strong>here is my First Activity:</strong></p>
  
  <pre><code>       public void loadHeroList() {
  
          //getting the progressbar
          final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
          //making the progressbar visible
          progressBar.setVisibility(View.VISIBLE);
  
          StringRequest stringRequest= new StringRequest(Request.Method.GET, "http://182.18.163.39/train/m/list_details.php?username="+user+"&amp;key="+pass,
                  new Response.Listener&lt;String&gt;(){
                      @Override
                      public void onResponse(String response) {
                          //hiding the progressbar after completion
                          progressBar.setVisibility(View.INVISIBLE);
  
                          try {
  
                              JSONArray jsonarray = new JSONArray(response);
                              for (int i = 0; i &lt; jsonarray.length(); i++) {
                                  JSONObject jsonobject = jsonarray.getJSONObject(i);
                                  String name = jsonobject.getString("Sno");
                                  String Tktid = jsonobject.getString("TKTID");
                                  link = jsonobject.getString("Link");
                                  status = jsonobject.getString("Status");
  
                                  List list = new List(user, pass, jsonobject.getString("Sno"), jsonobject.getString("TKTID"),jsonobject.getString("Link"),jsonobject.getString("Status"));
                                  tktList.add(list);
  
                                  Log.i("website content", name);
                                  Log.i("website content", Tktid);
                                  Log.i("website content", link);
  
                              }
  
                              //creating custom adapter object
                              ListViewAdapter adapter = new ListViewAdapter(tktList, getApplicationContext());
  
                              //adding the adapter to listview
                              listView.setAdapter(adapter);
  
  //                            adapter = (ListViewAdapter) listView.getAdapter();
  //                            List item = adapter.getItem(0);
  //                            adapter.remove(item);
  //                            adapter.notifyDataSetChanged();
  
                          } catch (JSONException e) {
                              e.printStackTrace();
                          }
  </code></pre>
  
  <p><strong>List Adapter:</strong></p>
  
  <pre><code> final Button btupdate = listViewItem.findViewById(R.id.btupdate);
  //        Button btview = listViewItem.findViewById(R.id.btview);
          final List hero = tktList.get(position);
  
          btupdate.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent i = new Intent(mCtx, Main2Activity.class);
                  i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  
                  i.putExtra("Link", hero.getLink());
                  i.putExtra("Status", hero.getStatus());
                  i.putExtra("username", hero.getUsername());
                  i.putExtra("password", hero.getPassword());
                  mCtx.startActivity(i);
  
              }
  
          });
  
          //Getting the hero for the specified position
          //setting hero values to textviews
          textViewName.setText(hero.getSno());
          textViewImageUrl.setText(hero.getTktid());
          //returning the listitem
  
  
          return listViewItem;
      }
  </code></pre>
  
  <p><strong>And my Second Activity:</strong></p>
  
  <pre><code>  btnupdate = (Button) findViewById(R.id.btnupdate);
  
          btnupdate.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  etupdate = ((EditText) findViewById(R.id.EditTextUpdate)).getText().toString();
                  action = etupdate;
  
                  ticketid = message;
  
                  if (status.equalsIgnoreCase("Pending")) {
  
                      try {
                          action = URLEncoder.encode(action,"UTF-8");
                      } catch (UnsupportedEncodingException e) {
                          e.printStackTrace();
                      }
  
                      try {
                          int l = etupdate.length();
                          if (l != 0) {
                              url = "http://182.18.163.39/train/m/action.php?username=" + username + "&amp;key=" + password + "&amp;tktid=" + ticketid + "==&amp;action=" + action;
                          } else
                              url = "http://182.18.163.39/train/m/action.php?username=" + username + "&amp;key=" + password + "&amp;tktid=" + ticketid + "==&amp;action=";
  
                          HttpClient httpClient = new DefaultHttpClient();
                          HttpGet httpPost = new HttpGet(url);
                          HttpResponse response = httpClient.execute(httpPost);
                          HttpEntity entity = response.getEntity();
  
                          String responseString = EntityUtils.toString(entity);
  
                          JSONArray jsonarray = new JSONArray(responseString);
                          JSONObject jsonObj = new JSONObject();
                          jsonObj.put("Result", jsonarray);
                          String msg = jsonObj.getJSONArray("Result").getJSONObject(0).getString("Error");
  
                          String Successmsg = "Deficiency updated successfully.";
  
                          if (msg.equalsIgnoreCase(Successmsg)) {
  
                              onUpdatePressed(view);
  
                          } else {
                              Toast.makeText(getApplicationContext(), "failed to update", Toast.LENGTH_SHORT).show();
  
                          }
                      } catch (Exception e) {
                          Toast.makeText(getApplicationContext(), "Network Failed", Toast.LENGTH_SHORT).show();
                      }
                  }
                  else {
                      Toast.makeText(getApplicationContext(), "Already updated you are not allow to update", Toast.LENGTH_SHORT).show();
                  }
              }
          });
      }
  
      public void onUpdatePressed(View view) {
  
  //        Intent i = new Intent(this, MainActivity.class);
  //        i.putExtra("UserName",username);
  //        i.putExtra("PassWord",password);
  //        startActivity(i);
          Toast.makeText(Main2Activity.this, "Successfully Updated", Toast.LENGTH_SHORT).show();
          MainActivity m = new MainActivity();
          m.loadHeroList();
          super.onBackPressed();
      }
  </code></pre>
  
  <p>here is my Error log:</p>
  
  <pre><code>03-08 11:10:36.902 9886-9886/com.example.lenovo.trainapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.example.lenovo.trainapp, PID: 9886
                                                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lenovo.trainapp/com.example.lenovo.trainapp.Main3Activity}: android.os.NetworkOnMainThreadException
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                 at android.os.Looper.loop(Looper.java:148)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                              Caused by: android.os.NetworkOnMainThreadException
                                                                                 at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)
                                                                                 at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:110)
                                                                                 at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
                                                                                 at libcore.io.IoBridge.connect(IoBridge.java:122)
                                                                                 at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
                                                                                 at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:452)
                                                                                 at java.net.Socket.connect(Socket.java:884)
                                                                                 at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:124)
                                                                                 at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:149)
                                                                                 at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
                                                                                 at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
                                                                                 at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:366)
                                                                                 at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
                                                                                 at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
                                                                                 at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470)
                                                                                 at com.example.lenovo.trainapp.Main3Activity.onCreate(Main3Activity.java:73)
                                                                                 at android.app.Activity.performCreate(Activity.java:6237)
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                 at android.os.Looper.loop(Looper.java:148) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  </code></pre>