title: Unfortunately, “app” has Stopped
body: <p>I am a new android coder. In this project, there is no red lines, but when i try to run my app, "Unfortunately, “app” has Stopped" pop on the screen. There are few yellow and purple line on the right though.
  here is my code:</p>
  
  <pre><code>import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.TextView;
  
  
  import android.app.Activity;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.Spinner;
  import android.widget.AdapterView.OnItemSelectedListener;
  import android.widget.Button;
  
  public class Translator extends ActionBarActivity {
  
      public ArrayAdapter&lt;?&gt; fromLanguageAdapter, toLanguageAdapter, englishAdapter,
              chineseAdapter, spanishAdapter;
  
      public Spinner fromLanguageSpinner = (Spinner) findViewById(R.id.spinner);
      public Spinner toLanguageSpinner = (Spinner) findViewById(R.id.spinner2);
      public Spinner phrases = (Spinner) findViewById(R.id.spinner3);
      public TextView answer = (TextView)findViewById(R.id.answer);
      public String[][] allPhrases = new String[][]{{"Hello","thank you","you are welcome","goodbye","i love you"},
              {"你好","谢谢","不用客气","再见","我爱你"},
              {"hola","gracias","bienvenido","adiós","te amo"}};
      public Button button = (Button) findViewById(R.id.button);
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_translator);
  
          fromLanguageAdapter = ArrayAdapter.createFromResource(this,R.array.fromLanguage,
                  android.R.layout.simple_spinner_item);
          fromLanguageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          fromLanguageSpinner.setAdapter(fromLanguageAdapter);
          fromLanguageSpinner.setOnItemSelectedListener(new languageListener());
  
          toLanguageAdapter =  ArrayAdapter.createFromResource(this,R.array.toLanguage,
                  android.R.layout.simple_spinner_item);
          toLanguageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          toLanguageSpinner.setAdapter(toLanguageAdapter);
          button.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  translate();
              }
          });
      }
  
      public class languageListener implements OnItemSelectedListener{
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View v, int pos,
                                     long id) {
  
              //parent.getItemAtPosition(pos);
  
              if (pos==0)
                  chooseEnglish(phrases);
              else if (pos==1)
                  chooseChinese(phrases);
              else if (pos==2)
                  chooseSpanish(phrases);
          }
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
          }
      }
  
  
      private void chooseEnglish(Spinner spinner){
          englishAdapter = ArrayAdapter.createFromResource(this,R.array.englishPhrases,
                  android.R.layout.simple_spinner_item);
          englishAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner.setAdapter(englishAdapter);
      }
  
      private void chooseChinese(Spinner spinner){
          chineseAdapter = ArrayAdapter.createFromResource(this,R.array.chinesePhrases,
      android.R.layout.simple_spinner_item);
          chineseAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spinner.setAdapter(chineseAdapter);
  }
  
      private void chooseSpanish(Spinner spinner){
          spanishAdapter = ArrayAdapter.createFromResource(this,R.array.spanishPhrases,
                  android.R.layout.simple_spinner_item);
          spanishAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner.setAdapter(spanishAdapter);
      }
  
      void translate(){
          int toLanguagePosition = toLanguageSpinner.getSelectedItemPosition();
          int whichPhrase = phrases.getSelectedItemPosition();
          answer.setText(allPhrases[toLanguagePosition][whichPhrase]);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_translator, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>and here is the xml file:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
      android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Translator"&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="From:"
          android:id="@+id/textView"
          android:layout_alignParentTop="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;Spinner
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/spinner"
          android:layout_below="@+id/textView"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:spinnerMode="dropdown"
          android:entries="@array/fromLanguage" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="To:"
          android:id="@+id/textView2"
          android:layout_below="@+id/spinner"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;Spinner
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/spinner2"
          android:layout_below="@+id/textView2"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:entries="@array/toLanguage" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Phrases:"
          android:id="@+id/textView5"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_below="@+id/spinner2" /&gt;
  
      &lt;Spinner
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/spinner3"
          android:layout_below="@+id/textView5"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Translate"
          android:id="@+id/button"
          android:clickable="true"
          android:onClick="buttonOnClick"
          android:layout_alignParentBottom="true"
          android:layout_alignParentRight="true"
          android:layout_alignParentEnd="true" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:text="Large Text"
          android:id="@+id/answer"
          android:layout_below="@+id/spinner3"
          android:layout_toLeftOf="@+id/button"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>