title: How to Show Player's Name Using Spinner and Send by an Intent?
body: <p>I need your help. Can you help me resolving this project without encountering a "<strong>FATAL ERROR: Main</strong>" or something? I want to make a program that has the following steps:</p>
  
  <ol>
  <li><p><em>Register or sign-up a name for player one and two into the spinner. The EditText turn empty afterwards.</em></p></li>
  <li><p><em>Name(s) appeared on their respective spinners. (Duplication of names is OK for me for player one and player two)</em></p></li>
  <li><p><em>Whatever the player's name selected on the spinner and if I click "Set your name(s) and  play!" button, the intent calls for another .class for the result.</em></p></li>
  </ol>
  
  <p>The only thing I didn't expected is the annoying <strong>FORCE CLOSE</strong> error even if I got no errors. Here's my sample:</p>
  
  <p>Here's my code for the main class (<strong>AndroidSpinnerFromSQLiteActivity</strong>):</p>
  
  <pre><code>//Variables
      private Spinner spinner, spinner_2;
      private Button add_button, add_button_2;
      private EditText label_input, label_input_2;
  
      //Response
      public final static String EXTRA_MESSAGE_ONE = "com.example.databasetest.MESSAGEONE";
      public final static String EXTRA_MESSAGE_TWO = "com.example.databasetest.MESSAGETWO";
  
      @Override
      public void onCreate(Bundle savedInstanceState) 
      {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          //Identifying view by looking for the player 1 view's ID.
          spinner = (Spinner) findViewById(R.id.Player_1_Spinner);
          add_button = (Button) findViewById(R.id.Player_1_Sign_up_Button);
          label_input = (EditText) findViewById(R.id.Player_1_Text_Field);
  
          //Identifying view by looking for the player 2 view's ID.
          spinner_2 = (Spinner) findViewById(R.id.Player_2_Spinner);
          add_button_2 = (Button) findViewById(R.id.Player_2_Sign_up_Button);
          label_input_2 = (EditText) findViewById(R.id.Player_2_Text_Field);
  
          //Adding the spinner listener...
          spinner.setOnItemSelectedListener(this);
          spinner_2.setOnItemSelectedListener(this);
  
          //Loading spinner's data from the database.
          loadSpinnerData();
  
          //Function for Buttons (Player 1)
          add_button.setOnClickListener(new OnClickListener() 
          {
  
              public void onClick(View v) 
              {
  
                  String label = label_input.getText().toString();
  
                  //Here's the process on how to register in the database.
                  if(label.trim().length() &gt; 0)
                  {
                      //Database Handler from Class (Database_Handler.java)
                      Database_Handler db = new Database_Handler(getApplicationContext());
  
                      //Inserting new label into the database.
                      db.insertLabel(label);
  
                      //After typing, the text field is set to blank.
                      label_input.setText("");
  
                      //Normally, most smartphones and tablets only have a virtual keyboard.
                      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                      imm.hideSoftInputFromWindow(label_input.getWindowToken(), 0);
  
                      loadSpinnerData();
                  }
  
                  else //If the input is null...
                  {
                      Toast.makeText(getApplicationContext(), "Please enter your name, player 1!", Toast.LENGTH_SHORT).show();
                  }
  
              }
  
          });
  
        //Function for Buttons (Player 2)
          add_button_2.setOnClickListener(new OnClickListener() 
          {
  
              public void onClick(View v) 
              {
  
                  String label = label_input_2.getText().toString();
  
                  //Here's the process on how to register in the database.
                  if(label.trim().length() &gt; 0)
                  {
                      //Database Handler from Class (Database_Handler.java)
                      Database_Handler db = new Database_Handler(getApplicationContext());
  
                      //Inserting new label into the database.
                      db.insertLabel(label);
  
                      //After typing, the text field is set to blank.
                      label_input_2.setText("");
  
                      //Normally, most smartphones and tablets only have a virtual keyboard.
                      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                      imm.hideSoftInputFromWindow(label_input_2.getWindowToken(), 0);
  
                      loadSpinnerData();
                  }
  
                  else //If the input is null...
                  {
                      Toast.makeText(getApplicationContext(), "Please enter your name, player 2!", Toast.LENGTH_SHORT).show();
                  }
  
              }
  
          });
  
      }
  
  
  
  
  
      public void sendMessage(View v)
      {
          Intent intent = new Intent(this, Respond_Test.class);
  
          EditText P1 = (EditText) findViewById(R.id.Player_1_Text_Field);
          String message1 = P1.getText().toString();
  
          EditText P2 = (EditText) findViewById(R.id.Player_2_Text_Field);
          String message2 = P2.getText().toString();
  
          intent.putExtra(EXTRA_MESSAGE_ONE, message1);
          intent.putExtra(EXTRA_MESSAGE_TWO, message2);
          startActivity(intent);
      }
  
  
  
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) 
      {
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  
  
  
  
      //Now, call a method called loadSpinnerData() from the onCreate() method.
      private void loadSpinnerData()
      {
  
          Database_Handler db = new Database_Handler(getApplicationContext());
  
          List&lt;String&gt; lables = db.getAllLabels();
  
          //Creating an adapter for the spinner...
          ArrayAdapter&lt;String&gt; data_adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, lables);
  
          data_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
          spinner.setAdapter(data_adapter);
          spinner_2.setAdapter(data_adapter);
  
      }
  
  
  
  
  
      //Action applied if a user chose this item.
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) 
      {
  
          String label = parent.getItemAtPosition(position).toString();
  
          Toast.makeText(parent.getContext(), "You selected: " + label,
                  Toast.LENGTH_LONG).show();
  
      }
  
  
  
  
  
      public void onNothingSelected(AdapterView&lt;?&gt; arg0) 
      {
  
          //Do nothing. I guess...
  
      }
  </code></pre>
  
  <p>Here's another code for the response of displaying names on another class (<strong>Respond_Test</strong>):</p>
  
  <pre><code>@Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
  
          Intent intent = getIntent();
          String messageone = intent.getStringExtra(AndroidSpinnerFromSQLiteActivity.EXTRA_MESSAGE_ONE);
          String messagetwo = intent.getStringExtra(AndroidSpinnerFromSQLiteActivity.EXTRA_MESSAGE_TWO);
  
          TextView P1 = (TextView) findViewById(R.id.Player_1_ID);
          TextView P2 = (TextView) findViewById(R.id.Player_2_ID);
  
          P1.setText(messageone);
          P2.setText(messagetwo);
          setContentView(R.layout.respond);
      }
  </code></pre>
  
  <p>The XML of the main (<strong>main.xml</strong>):</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" &gt;
  
      &lt;LinearLayout
          android:id="@+id/linearLayout1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:layout_marginTop="41dp" &gt;
  
          &lt;TextView
              android:id="@+id/textView1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Enter Player 1 Name:" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/linearLayout2"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/linearLayout1" &gt;
  
          &lt;EditText
              android:id="@+id/Player_1_Text_Field"
              android:layout_width="0dp"
              android:layout_height="35dp"
              android:layout_weight="1"
              android:inputType="textNoSuggestions"
              android:textSize="@dimen/padding_large" &gt;
  
              &lt;requestFocus /&gt;
          &lt;/EditText&gt;
  
          &lt;Button
              android:id="@+id/Player_1_Sign_up_Button"
              android:layout_width="70dp"
              android:layout_height="35dp"
              android:text="@string/Sign_Up"
              android:textSize="@dimen/padding_medium" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/linearLayout3"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/linearLayout2" &gt;
  
          &lt;Spinner
              android:id="@+id/Player_1_Spinner"
              android:layout_width="wrap_content"
              android:layout_height="37dp"
              android:layout_weight="1"
              android:prompt="@string/PLAYER_1_PROMPT"
              tools:listitem="@android:layout/simple_spinner_dropdown_item" /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/linearLayout4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/linearLayout3" &gt;
  
          &lt;TextView
              android:id="@+id/TextView01"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="41dp"
              android:text="Enter Player 2 Name:" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/linearLayout5"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/linearLayout4" &gt;
  
          &lt;EditText
              android:id="@+id/Player_2_Text_Field"
              android:layout_width="0dp"
              android:layout_height="35dp"
              android:layout_weight="5.47"
              android:inputType="textPersonName" /&gt;
  
          &lt;Button
              android:id="@+id/Player_2_Sign_up_Button"
              android:layout_width="70dp"
              android:layout_height="35dp"
              android:text="@string/Sign_Up"
              android:textSize="@dimen/padding_medium" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/linearLayout5" &gt;
  
          &lt;Spinner
              android:id="@+id/Player_2_Spinner"
              android:layout_width="wrap_content"
              android:layout_height="37dp"
              android:layout_weight="1"
              android:prompt="@string/PLAYER_2_PROMPT" /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="34dp"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="62dp"
          android:text="@string/GAME"
          android:onClick="sendMessage" /&gt;
  
  &lt;/RelativeLayout&gt;
  
  
  
  XML for the response (**respond.xml**):
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
  
  
      &lt;TextView
          android:id="@+id/Player_1_ID"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:layout_marginLeft="16dp"
          android:layout_marginTop="64dp"
          android:text="TextView"
          android:textSize="20sp" /&gt;
  
  
  
      &lt;TextView
          android:id="@+id/Player_2_ID"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/Player_1_ID"
          android:layout_below="@+id/Player_1_ID"
          android:layout_marginTop="24dp"
          android:text="TextView"
          android:textSize="20sp" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And the manifest:</p>
  
  <pre><code>    &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.databasetest"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
  
  
  
  
  
      &lt;uses-sdk
          android:minSdkVersion="4"
          android:targetSdkVersion="15" /&gt;
  
  
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
  
  
  
          &lt;activity
              android:name=".AndroidSpinnerFromSQLiteActivity"
              android:label="@string/title_activity_android_spinner_from_sqlite"
              android:theme="@style/AppTheme"&gt;"
  
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
  
          &lt;/activity&gt;
  
  
  
           &lt;activity
              android:name=".Respond_Test"
              android:label="@string/title_activity_android_spinner_from_sqlite"
              android:theme="@style/AppTheme"/&gt;"
  
  
  
      &lt;/application&gt;
  
  
  
  
  
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Hope you can help me and thanks in advance.</p>