title: Fatal Exception AsyncTask #1 and Android doInBackground()
body: <p>Good morning StackOver Flow Pros,</p>
  
  <p>I need a little help here. I am running an Android application which calls out to a MySql database via a php script, When I run the application I get a Fatal Exception error for AsyncTask #1 caused by, a null pointer exception. It said it occurred while executing doInBackground. This is a tutorial I am following from MyBringBack. I really need to wrap my head around this because I have been trying to figure this out for days. If I remove/comment most of the Log.d statements it will run fine but I will not see the tags for what is going on from the JSON responses, the code is listed below, could anyone help me figure this out or tell me what is wrong with the code.</p>
  
  <p>Here is the error log from logcat</p>
  
  <blockquote>
    <p>10-25 09:27:47.818: E/JSON Parser(1041): Error parsing data org.json.JSONException: Value array(2) of type java.lang.String cannot be converted to JSONObject
    10-25 09:27:47.818: W/dalvikvm(1041): threadid=11: thread exiting with uncaught exception (group=0xb1b06ba8)
    10-25 09:27:47.828: E/AndroidRuntime(1041): FATAL EXCEPTION: AsyncTask #1
    10-25 09:27:47.828: E/AndroidRuntime(1041): Process: com.bobcatservice, PID: 1041
    10-25 09:27:47.828: E/AndroidRuntime(1041): java.lang.RuntimeException: An error occured while executing doInBackground()
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at android.os.AsyncTask$3.done(AsyncTask.java:300)
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at java.lang.Thread.run(Thread.java:841)
    10-25 09:27:47.828: E/AndroidRuntime(1041): Caused by: java.lang.NullPointerException
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at com.bobcatservice.Login$AttemptLogin.doInBackground(Login.java:126)
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at com.bobcatservice.Login$AttemptLogin.doInBackground(Login.java:1)
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
    10-25 09:27:47.828: E/AndroidRuntime(1041):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    10-25 09:27:47.828: E/AndroidRuntime(1041):     ... 4 more
    10-25 09:27:49.968: E/WindowManager(1041): android.view.WindowLeaked: Activity com.bobcatservice.Login has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b1e8e430 V.E..... R......D 0,0-684,192} that was originally added here
    10-25 09:27:49.968: E/WindowManager(1041):  at android.view.ViewRootImpl.(ViewRootImpl.java:348)
    10-25 09:27:49.968: E/WindowManager(1041):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
    10-25 09:27:49.968: E/WindowManager(1041):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
    10-25 09:27:49.968: E/WindowManager(1041):  at android.app.Dialog.show(Dialog.java:286)</p>
  </blockquote>
  
  <p>And here is the code in question</p>
  
  <pre><code>//AsyncTask is a seperate thread than the thread that runs the GUI
  //Any type of networking should be done with asynctask.
  class AttemptLogin extends AsyncTask&lt;String, String, String&gt; {
  
       /**
      * Before starting background thread Show Progress Dialog
      * */
      boolean failure = false;
  
     @Override
     protected void onPreExecute() {
         super.onPreExecute();
         pDialog = new ProgressDialog(Login.this);
         pDialog.setMessage("Attempting login...");
         pDialog.setIndeterminate(false);
         pDialog.setCancelable(true);
         pDialog.show();
     }
  
      @Override
      protected String doInBackground(String... args) {
          // TODO Auto-generated method stub
           // Check for success tag
         int success;
         String username = user.getText().toString();
         String password = pass.getText().toString();
  
             // Building Parameters
             List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
             params.add(new BasicNameValuePair("username", username));
             params.add(new BasicNameValuePair("password", password));
  
             Log.d("request!", "starting");
             // getting product details by making HTTP request
             JSONObject json = jsonParser.makeHttpRequest(
                    LOGIN_URL, "POST", params);
  
             try {
             // check your log for json response
             Log.d("Login attempt", json.toString());
  
             // json success tag
             success = json.getInt(TAG_SUCCESS);
             if (success == 1) {
              Log.d("Login Successful!", json.toString());
              Intent i = new Intent(Login.this, Welcome.class);
              finish();
              startActivity(i);
              return json.getString(TAG_MESSAGE);
              }else{
              Log.d("Login Failure!", json.getString(TAG_MESSAGE));
              return json.getString(TAG_MESSAGE);
  
             }
          } catch (JSONException e) {
             e.printStackTrace();
         }
  
         return null;
  
      }
      /**
      * After completing background task Dismiss the progress dialog
      * **/
     protected void onPostExecute(String file_url) {
         // dismiss the dialog once product deleted
         pDialog.dismiss();
         if (file_url != null){
          Toast.makeText(Login.this, file_url, Toast.LENGTH_LONG).show();
         }
  
     }
  
  }
  </code></pre>
  
  <p>}</p>