title: Android Calling Async task inside another Async task?
body: <p>I'm trying to do an Async call inside of another Async method I am not sure if I'm doing this correctly, or if it's even possible. First call gets the partID's from the database, and then second gets the lotNumbers of the part's. My reasoning for doing this is to be able to loop through and put the associated partLotNumebrs inside a Spinner and display a list of Spinners in a Listview. what am I doing wrong? Is this even possible? I know you can't make HTTP calls inside the main so I'm not sure of any other way to do this. </p>
  
  <p>the error I'm getting.</p>
  
  <pre><code>02-13 11:04:16.431: E/AndroidRuntime(1369): FATAL EXCEPTION: main
  02-13 11:04:16.431: E/AndroidRuntime(1369): java.lang.NullPointerException
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at com.cbs.iomamobile.ViewOrderlineAssemblyActivity$getPartLotNumbers.onPostExecute(ViewOrderlineAssemblyActivity.java:258)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at com.cbs.iomamobile.ViewOrderlineAssemblyActivity$getPartLotNumbers.onPostExecute(ViewOrderlineAssemblyActivity.java:1)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at android.os.AsyncTask.finish(AsyncTask.java:602)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at android.os.AsyncTask.access$600(AsyncTask.java:156)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at android.os.Handler.dispatchMessage(Handler.java:99)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at android.os.Looper.loop(Looper.java:137)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at android.app.ActivityThread.main(ActivityThread.java:4340)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at java.lang.reflect.Method.invokeNative(Native Method)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at java.lang.reflect.Method.invoke(Method.java:511)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  02-13 11:04:16.431: E/AndroidRuntime(1369):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>it's pointing to this line </p>
  
  <pre><code>textView.setText(temp.getString("name"));
  </code></pre>
  
  <p>it seems neither my Spinner or textView are valid, no idea why.</p>
  
  <p>assembly.class</p>
  
  <pre><code>public class ViewOrderlineAssemblyActivity extends ListActivity{
      // Progress Dialog
      private ProgressDialog pDialog;
  
      String productName;
      String olid;
      String assemblyName;
  
      // Creating JSON Parser object
      JSONParser jsonParser = new JSONParser();
  
      // url to get all orders list
      private static String url_get_assembly_parts = "http://10.0.2.2/android_connect/get_assembly_parts.php";
  
      // url to get all orders list
      private static String url_get_part_partlotnumbers = "http://10.0.2.2/android_connect/get_part_partLotNumbers.php";
  
  
  
      // orders JSONArray
      JSONArray assembly = null;
      JSONArray parts = null;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.all_assemblies);
  
          // getting product details from intent
          Intent i = getIntent();
  
          // getting product id (pid) from intent
          assemblyName = i.getStringExtra("assemblyName");
          olid = i.getStringExtra(TAG_OLID);
  
          Log.d("assemblyName", "" + assemblyName);
  
          // Loading orders in Background Thread
          new LoadAllAssemblyParts().execute();
  
  
  
      }
  
      // Response from Edit Order Activity
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          // if result code 100
          if (resultCode == 100) {
              // if result code 100 is received 
              // means user edited/deleted product
              // reload this screen again
              Intent intent = getIntent();
              finish();
              startActivity(intent);
          }
  
      }
  
      /**
       * Background Async Task to Load all assemblyparts by making HTTP Request
       * */
      class LoadAllAssemblyParts extends AsyncTask&lt;String, String, String&gt; {
  
          @Override
          protected void onPreExecute() {
          }
  
          /**
           * getting All orders from url
           * */
          protected String doInBackground(String... args) {
              // Building Parameters
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
              params.add(new BasicNameValuePair("assemblyName", assemblyName));   
  
              // getting JSON string from URL
              JSONObject json = jsonParser.makeHttpRequest(url_get_assembly_parts, "GET", params);
  
              // Check log cat for JSON reponse
              Log.d("All partID's: ", json.toString());
  
              try {
                  // Checking for SUCCESS TAG
                  int success = json.getInt(TAG_SUCCESS);
  
                  if (success == 1) {
                      // orders found
                      // Getting Array of Parts
                      assembly = json.getJSONArray("assembly");
  
                      // looping through All Parts
                      for (int i = 0; i &lt; assembly.length(); i++) {
  
                          JSONObject c = assembly.getJSONObject(i);
  
                          // Storing each json item in variable
                          String id = c.getString("partID");
                          String name = c.getString("assemblyName");
  
                          new getPartLotNumbers().execute(id);
                      }
                  } else {
                      // no part ID's found
  
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
              return null;
          }
  
          /**
           * After completing background task Dismiss the progress dialog
           * **/
          protected void onPostExecute(String file_url) {
              // dismiss the dialog after getting all orders
          }
  
      }
  
      class getPartLotNumbers extends AsyncTask&lt;String, String, JSONArray&gt;{
  
          Spinner spinner;
          TextView textView;
  
          @Override
          protected JSONArray doInBackground(String... args) {            
  
              JSONArray parts = null;
              int success;
              String partID = args[0];
  
              try{
                  // Building Parameters 
                  List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
                  params.add(new BasicNameValuePair("partID", partID));
  
                  // getting part Lot Numbers by making HTTP request
                  // Note that part Lot Numbers will use GET request
                  JSONObject json = jsonParser.makeHttpRequest(url_get_part_partlotnumbers, "GET", params);
  
                  // check log for json response
                  Log.d("List of PartID's", json.toString());
  
                  // json success tag
                  success = json.getInt(TAG_SUCCESS);
  
                  if(success == 1){
  
                      // successfully received part Lot Numbers
                      parts = json.getJSONArray("parts"); // JSON Array
  
                  }else{
                      // part Lot Numbers not not found
                  }
  
              }catch(JSONException e){
                  e.printStackTrace();
              }
  
              //return array of part Lot Numbers
              return parts;
          }
  
          protected void onPostExecute(JSONArray products){
              //spinner and textview
              spinner = (Spinner) findViewById(R.id.LotNumbers);
              textView = (TextView) findViewById(R.id.partName);
  
              //list of partLotNumbers
              List&lt;String&gt; partLotNumberList = new ArrayList&lt;String&gt;();
  
              //move list from JSON to List
              try{
                  for(int i=0;i&lt;products.length();i++){
                      JSONObject temp = products.getJSONObject(i);
  
                      partLotNumberList.add(temp.getString("partLotNumber"));
              }
  
              //get Part Name
              JSONObject temp = products.getJSONObject(0);
              textView.setText(temp.getString("name"));
  
              } catch(JSONException e){
                  e.printStackTrace();
              }
  
              //adapter for Spinner           
              ArrayAdapter&lt;String&gt; adp1=new ArrayAdapter&lt;String&gt;(getBaseContext(), android.R.layout.simple_list_item_1, partLotNumberList);           
              adp1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
              //set the adapter to the spinnner
              spinner.setAdapter(adp1);                       
          }
  
      }
  }
  </code></pre>
  
  <p>all_assembly_parts.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
  &lt;!-- Main ListView 
           Always give id value as list(@android:id/list)
      --&gt;
      &lt;ListView
          android:id="@android:id/list"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>view_assembly_parts.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/partName"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="TextView" /&gt;
  
      &lt;Spinner
          android:id="@+id/LotNumbers"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>