title: Populating Spinner using string values returned by SOAP web service
body: <p>I am working on a Android code that returns me String values that I store in a String array.I want to use this String array to populate one of my Spinners.</p>
  
  <p>My main intention is that depending on what the user selects in 1st spinner , I want to populate my 2nd spinner using my String array.</p>
  
  <blockquote>
    <p>However, when I try I am getting a NullPointerException  even when I am populating the adapter</p>
  </blockquote>
  
  <p>My Android code: </p>
  
  <pre><code>public class Mark2 extends Activity 
  {
    private static final String SOAP_ACTION = "http://tempuri.org/getData";
    private static final String METHOD_NAME = "getData";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://10.0.2.2/getsubject/Service1.asmx"; 
  
  
    private Spinner s;
    private Spinner s2;
    private Spinner s3;
  
  @Override
      protected void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.mainspinner);
  
      s = (Spinner) findViewById(R.id.spinner1);
      s2 = (Spinner) findViewById(R.id.spinner2);
  
  
      String[] myList4=call();
      for(int i=0;i&lt;myList4.length;i++)
      System.out.println(myList4[i]);
  
      String[] myList = new String[] {"First half","Second Half"};
      String[] myList2=new  String[] {
                                             "abc",
                                     "ghf", 
                                     "ijk",                             
                                     };
  
      String[] myList3=new String[]  {
                              "john",
                              "ann", 
                              "joe",
  
                                     };
  
     s.setAdapter(new ArrayAdapter&lt;String&gt; (this,android.R.layout.simple_spinner_item, myList));
      s2.setAdapter(new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item, myList2));
  
  
      final ArrayAdapter&lt;String&gt; adapter3 = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item, myList4);
      final ArrayAdapter&lt;String&gt; adapter2 = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item, myList3);
  
  
      s.setOnItemSelectedListener(new OnItemSelectedListener()
      {
  
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View v,int pos, long id) 
          {
  
          if(parent.getItemAtPosition(pos).toString().equalsIgnoreCase("First half"))
          {
             s2.setSelection(pos);
             s3.setAdapter(adapter3);
          }
          else
          {
              s2.setAdapter(adapter2);
              s2.setSelection(pos);
  
  
          }
  
          }
  
  
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
  
  
          }});
  
  
  }
  
  public String[] call()
  {
      SoapPrimitive responsesData = null; 
  
      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
  
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( 
      SoapEnvelope.VER11); 
      envelope.dotNet = true; 
      envelope.setOutputSoapObject(request);
  
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
  
      androidHttpTransport.debug = true; 
  
      try {
  
      androidHttpTransport.call(SOAP_ACTION, envelope);
  
      responsesData = (SoapPrimitive) envelope.getResponse(); 
      System.out.println(" --- response ---- " + responsesData); 
  
      } catch (SocketException ex) { 
      ex.printStackTrace(); 
      } catch (Exception e) { 
      e.printStackTrace(); 
      } 
  
      System.out.println( " ----" + responsesData );
  
      String serviceResponse= responsesData .toString(); 
  
  
      String[] temp; 
      String delimiter = "#"; 
      temp= serviceResponse.split(delimiter);
      System.out.println( " ---- length ---- " + temp.length); 
  
      return temp; 
  
  
     }      
  
  
    }
  </code></pre>
  
  <p>My logcat:</p>
  
  <pre><code> 11-17 15:51:09.668: DEBUG/dalvikvm(125): GC_EXPLICIT freed 1220 objects / 68272 bytes in 164ms
   11-17 16:20:29.649: ERROR/AndroidRuntime(620): java.lang.NullPointerException
   11-17 16:20:29.649: ERROR/AndroidRuntime(620):     at com.example.Mark2$1.onItemSelected(Mark2.java:88)
   11-17 16:20:29.649: ERROR/AndroidRuntime(620):     at android.widget.AdapterView.fireOnSelected(AdapterView.java:864)
   11-17 16:20:29.649: ERROR/AndroidRuntime(620):     at android.widget.AdapterView.access$200(AdapterView.java:42)
   11-17 16:20:29.649: ERROR/AndroidRuntime(620):     at  android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:830)
   11-17 16:20:29.649: ERROR/AndroidRuntime(620):     at android.os.Handler.handleCallback(Handler.java:587)  
   11-17 16:20:29.649: ERROR/AndroidRuntime(620):     at android.os.Handler.dispatchMessage(Handler.java:92)
  </code></pre>
  
  <blockquote>
    <p>Edit: Line no: 88 is  s3.setAdapter(adapter3);</p>
  </blockquote>