title: Fatal error during executing android app
body: <p>Why the app gets unfortunately stopped ??</p>
  
  <p>Error is :</p>
  
  <pre><code> java.lang.RuntimeException: An error occured while executing doInBackground()
   at android.os.AsyncTask$3.done(AsyncTask.java:300)
   at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
   at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
   at java.util.concurrent.FutureTask.run(FutureTask.java:242)
   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
   at java.lang.Thread.run(Thread.java:841)
   Caused by: java.lang.NullPointerException
   at com.example.prateek.urbanityc.Bg.doInBackground(Bg.java:45)
   at com.example.prateek.urbanityc.Bg.doInBackground(Bg.java:24)
   at android.os.AsyncTask$2.call(AsyncTask.java:288)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  </code></pre>
  
  <p>The android code is :-</p>
  
  <p>.java file</p>
  
  <pre><code>   package com.example.prateek.urbanityc;
  
     import android.content.DialogInterface;
     import android.content.Intent;
     import android.support.v7.app.AlertDialog;
     import android.support.v7.app.AppCompatActivity;
     import android.os.Bundle;
     import android.view.View;
     import android.widget.Button;
     import android.widget.RadioButton;
     import android.widget.RadioGroup;
     import android.widget.TextView;
     import android.widget.Toast;
  
     public class choose_ngo extends AppCompatActivity implements 
      AsyncResponse {
      Button next, skip;
      TextView tv8;
      //String b;
      //GlobalVariable gb;
      String email, type1, type2;
  
  RadioGroup rg;
  String a,b;
  GlobalVariable gb;
  int selectedid;
  RadioButton rbvalue;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_choose_ngo);
  
      /*rg=(RadioGroup) findViewById(R.id.radiogroup);
      selectedid = rg.getCheckedRadioButtonId();
      rbvalue = (RadioButton) findViewById(selectedid);
      a=rbvalue.getText().toString();  */
  
      skip = (Button) findViewById(R.id.button2);
      next = (Button) findViewById(R.id.button6);
     // tv8 = (TextView) findViewById(R.id.textView8);
      gb = GlobalVariable.getSingleInstance();
  
  }
  
  public void verify(View view) {
  
      type1 = "store_ngo";
      type2 = "show_details";
      email = gb.getVariables().get("email");
  
      //Toast.makeText(this, email, Toast.LENGTH_SHORT).show();
      /*Toast.makeText(this, a, Toast.LENGTH_SHORT).show();
  
      Bg backgroundWorker = new BackgroundWorker(this, this);
      backgroundWorker.delegate = this;
      backgroundWorker.execute(type1, email,a);
       */
  
      back();
  
  
  
          }
  
  public void processFinish(String output) {
  
  
      AlertDialog.Builder builder = new AlertDialog.Builder(choose_ngo.this);
      builder.setTitle("Verify Details");
      builder.setMessage(output);
      builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              startActivity(new Intent(getApplicationContext(), thanku.class));
              finish();
  
          }
      });
      builder.setNegativeButton("Edit", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              startActivity(new Intent(getApplicationContext(), verify_details.class));
              finish();
          }
      });
  
      builder.show();
  }
  
  public void back()
  {
      Bg Bg = new Bg(this, this);
      Bg.delegate = this;
      Bg.execute(type2, email);
  }
  
  public void skip(View view) {
      email = gb.getVariables().get("email");
      back();
  
  
  }
  
  public void store() {
      b = getIntent().getExtras().getString("email2");
  }
   }
  </code></pre>
  
  <p>code for backgroundworker class</p>
  
  <pre><code>  package com.example.prateek.urbanityc;
  
    import android.app.AlertDialog;
    import android.app.ProgressDialog;
    import android.content.Context;
     import android.os.AsyncTask;
     import android.widget.Toast;
  
   import java.io.BufferedReader;
   import java.io.BufferedWriter;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.InputStreamReader;
   import java.io.OutputStream;
   import java.io.OutputStreamWriter;
   import java.net.HttpURLConnection;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.net.URLEncoder;
  
   public class Bg extends AsyncTask&lt;String,Void,String&gt; {
  
  Context context;
  AlertDialog alertDialog;
  
  AsyncResponse delegate;
  
  Bg(Context ctx, AsyncResponse delegate) {
      context = ctx;
      this.delegate = delegate;
  }
  
  @Override
  protected String doInBackground(String... params) {
      String type = params[0];
  
      String item_info_url = "http://urbanity.000webhostapp.com/item_typ.php";
      String show_info_url = "http://urbanity.000webhostapp.com/verify.php";
  
  
  
     if(type.equals("item_info")) {
  
          try {
  
              String email = params[1];
              String a = params[2];
              String b = params[3];
              String c = params[4];
  
              URL url = new URL(item_info_url);
              HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
              httpURLConnection.setRequestMethod("POST");
              httpURLConnection.setDoOutput(true);
              httpURLConnection.setDoInput(true);
              OutputStream outputStream = httpURLConnection.getOutputStream();
              BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
              String post_data =
                      URLEncoder.encode("email", "UTF-8") + "=" + URLEncoder.encode(email, "UTF-8") + "&amp;" +
                              URLEncoder.encode("a", "UTF-8") + "=" + URLEncoder.encode(a, "UTF-8") + "&amp;" +
                              URLEncoder.encode("b", "UTF-8") + "=" + URLEncoder.encode(b, "UTF-8") + "&amp;" +
                              URLEncoder.encode("c", "UTF-8") + "=" + URLEncoder.encode(c, "UTF-8");
              bufferedWriter.write(post_data);
              bufferedWriter.flush();
              bufferedWriter.close();
              outputStream.close();
              InputStream inputStream = httpURLConnection.getInputStream();
              BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
              String result = "";
              String line = "";
              while ((line = bufferedReader.readLine()) != null) {
                  result += line;
              }
              bufferedReader.close();
              inputStream.close();
              httpURLConnection.disconnect();
              return result;
          }
          catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      else if(type.equals("show_details")) {
  
          try {
  
              String email = params[1];
  
              URL url = new URL(show_info_url);
              HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
              httpURLConnection.setRequestMethod("POST");
              httpURLConnection.setDoOutput(true);
              httpURLConnection.setDoInput(true);
              OutputStream outputStream = httpURLConnection.getOutputStream();
              BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
              String post_data =
                      URLEncoder.encode("email", "UTF-8") + "=" + URLEncoder.encode(email, "UTF-8");
  
              bufferedWriter.write(post_data);
              bufferedWriter.flush();
              bufferedWriter.close();
              outputStream.close();
              InputStream inputStream = httpURLConnection.getInputStream();
              BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
              String result = "";
              String line = "";
              while ((line = bufferedReader.readLine()) != null) {
                  result += line;
              }
              bufferedReader.close();
              inputStream.close();
              httpURLConnection.disconnect();
              return result;
          }
          catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      return null;
  }
  
  @Override
  protected void onPreExecute() {
      alertDialog = new AlertDialog.Builder(context).create();
      alertDialog.setTitle("Login Status");
  }
  
  
  @Override
  
  protected void onPostExecute(String result) {
  
      alertDialog.setMessage(result);
      if(result!=null){
          delegate.processFinish(result); }
      //alertDialog.show();
  
  }
  @Override
  protected void onProgressUpdate(Void... values) {
      super.onProgressUpdate(values);
  }
    }
  </code></pre>
  
  <p>.xml file </p>
  
  <pre><code>     &lt;?xml version="1.0" encoding="utf-8"?&gt;
       &lt;RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       xmlns:tools="http://schemas.android.com/tools"
       android:id="@+id/activity_choose_ngo"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
          android:paddingBottom="16dp"
       android:paddingLeft="64dp"
       android:background="@drawable/giving"
       android:paddingRight="64dp"
       android:paddingTop="16dp"
       tools:context="com.example.prateek.urbanityc.choose_ngo"&gt;
  
      &lt;Button
       android:id="@+id/button2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/radiogroup"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="37dp"
      android:layout_alignParentLeft="true"
      android:text="SKIP"
      android:textStyle="bold"
      android:onClick="skip"
      /&gt;
  
  &lt;TextView
      android:id="@+id/textView4"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="18dp"
      android:text="NGOs AVAILABLE "
      android:textSize="25dp"
  
      android:textStyle="bold"
      android:textColor="#0000FF"
      android:layout_below="@+id/textView3"
      android:layout_centerHorizontal="true" /&gt;
      &lt;RadioGroup
      android:layout_width="wrap_content"
      android:id="@+id/radiogroup"
      android:layout_height="wrap_content"
      android:layout_marginTop="50dp"
      android:layout_below="@+id/textView3"&gt;
  
  
      &lt;RadioButton
          android:id="@+id/radioButton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="35dp"
          android:textSize="20dp"
          android:text="Gramiksha"
          android:layout_below="@+id/textView4"
          /&gt;
  
      &lt;RadioButton
          android:id="@+id/radioButton2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="15dp"
          android:textSize="20dp"
          android:text="Pryatna"
          android:layout_below="@+id/radioButton"
          /&gt;
  
      &lt;RadioButton
          android:id="@+id/radioButton3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="AshaKiran"
          android:layout_marginTop="12dp"
          android:textSize="20dp"
          android:layout_below="@+id/radioButton2"
          /&gt;
  
      &lt;RadioButton
          android:id="@+id/radioButton4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="15dp"
          android:text="Udan"
          android:textSize="20dp"
          android:layout_below="@+id/radioButton3"
          /&gt;
  &lt;/RadioGroup&gt;
  
  &lt;Button
      android:id="@+id/button6"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="NEXT"
      android:textStyle="bold"
      android:onClick="verify"
      android:layout_alignTop="@+id/button2"
      android:layout_alignParentRight="true"
      android:layout_alignParentEnd="true" /&gt;
  
  &lt;!-- &lt;TextView
      android:layout_width="40dp"
      android:layout_height="40dp"
      android:text="Skip"
      android:textSize="20dp"
      android:textStyle="bold"
      android:layout_alignBottom="@+id/textView4"
      android:layout_marginBottom="22dp"
      android:id="@+id/textView8"
      android:layout_alignParentTop="true"
      android:onClick="skip"
      android:layout_alignParentRight="true"
      android:layout_alignParentEnd="true" /&gt;  --&gt;
  
     &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>php file</p>
  
  <pre><code>   &lt;?php
     require "con1.php";
  
     $email=$_POST["email"];
      $contact='';
    $add='';
     //$c=$_POST["c"]; 
  
     require_once('con1.php') ;
  
     $sql = "SELECT u_contact,u_add FROM user where u_mail = '$email' ";
  
     if ($result=mysqli_query($conn,$sql))
         {
       // Fetch one and one row
      while ($row=mysqli_fetch_row($result))
        {
           echo "Contact: ".$row[0];
           echo "                           ";
          echo "Address: ".$row[1];
          }
       }
  
      // mysqli_close($conn);
  
       ?&gt;
  </code></pre>
  
  <p>The app is getting stop on clicking the skip button whereas it is running at all other clicks of buttons in app. I am not able to understand why is it happening i have done a lot of google to rectify the problem but i am unable to find the solution. So plzz help out me guys......</p>