title: Why spinner activity is not running? Error:Unfortunately spinnerapp has been stopped
body: <p>My problem is that when I run the spinner code it showed error that</p>
  <blockquote>
  <p>&quot;Unfortunately spinnerApp has been stopped&quot;</p>
  </blockquote>
  <p>Below is my XML file:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;
  tools:context=&quot;.MainActivity&quot;&gt;
  
  
  &lt;Spinner
      android:id=&quot;@+id/spinner&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;50dp&quot;
      android:layout_alignParentStart=&quot;true&quot;
      android:layout_alignParentTop=&quot;true&quot;
      android:layout_marginTop=&quot;113dp&quot;
      android:layout_alignParentLeft=&quot;true&quot; /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  <p>Below is my strings.xml:</p>
  <pre><code>&lt;resources&gt;
      &lt;string name=&quot;app_name&quot;&gt;SpinnerApp&lt;/string&gt;
      &lt;string-array name=&quot;myarray&quot;&gt;
          &lt;item value=&quot;Oswald&quot;&gt;Oswald&lt;/item&gt;
          &lt;item value=&quot;Noddy&quot;&gt;Noddy&lt;/item&gt;
          &lt;item value=&quot;Shinchan&quot;&gt;Shinchan&lt;/item&gt;
          &lt;item value=&quot;Doraemon&quot;&gt;Doraemon&lt;/item&gt;
          &lt;item value=&quot;Detective Conan&quot;&gt;Detective Conan&lt;/item&gt;
          &lt;item value=&quot;Power puff girls&quot;&gt;Power puff girls&lt;/item&gt;
          &lt;item value=&quot;Ojarumaru&quot;&gt;Ojarumaru&lt;/item&gt;
          &lt;item value=&quot;Bob the builder&quot;&gt;Bob the builder&lt;/item&gt;
          &lt;item value=&quot;Asari chan&quot;&gt;Asari chan&lt;/item&gt;
          &lt;item value=&quot;Maruko chan&quot;&gt;Maruko chan&lt;/item&gt;
          &lt;item value=&quot;Mighty masked cat niyander&quot;&gt;Mighty masked cat niyander&lt;/item&gt;
  
      &lt;/string-array&gt;
  &lt;/resources&gt;
  </code></pre>
  <p>below is my .java file:</p>
  <pre><code>package com.example.mypc.spinnerapp;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.*;
  import java.util.ArrayList;
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity {
      Spinner sp;
      ArrayAdapter adapter;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          sp=(Spinner)findViewById(R.id.spinner);
          List&lt;String&gt; list=new ArrayList&lt;String&gt;();
          list.add(&quot;Hello&quot;);
          list.add(&quot;World&quot;);
          list.add(&quot;How&quot;);
          list.add(&quot;are&quot;);
          list.add(&quot;you&quot;);
  
          String []arr=getResources().getStringArray(R.array.myarray);
          ArrayAdapter&lt;String&gt; adapter=new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item,list);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          sp.setAdapter(adapter);
          sp.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                 sp.setSelection(position);
             }
         });
      }
  }
  </code></pre>
  <p>What is wrong with my code?</p>