title: problem with screen/activities on button click
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6684499/setonclicklistener-not-working-and-throwing-error">setOnClickListener not working and throwing error</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to develop a discount calculator in which there will be a welcome screen and on button click, different calculator will work.</p>
  
  <p>Current I am not getting error but on click of:</p>
  
  <p><strong>button 1 - Calculator</strong>, I get error on phone <strong>"the application testcalculator stopped - force close"</strong></p>
  
  <p>when I  click <strong>button 2 - Calculator 2</strong>, I get nothing I don't know why.</p>
  
  <p>Only <strong>button 3</strong> - exit is working</p>
  
  <p><strong>Below is my complete code / programs:</strong></p>
  
  <p><strong>welcome.java</strong></p>
  
  <pre><code>    package com.testcalculator;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  
  
  
  
  
  public class welcome extends Activity implements OnClickListener
  {
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
          setContentView(R.layout.welcome1);
  
  
          //////// MENU  //////////
          Button playBtn = (Button) findViewById(R.id.playBtn);
          playBtn.setOnClickListener(this);
  
  
          Button playBtn2 = (Button) findViewById(R.id.playBtn2);
          playBtn2.setOnClickListener(this);
  
  
          Button exitBtn = (Button) findViewById(R.id.exitBtn);
          exitBtn.setOnClickListener(this);
  
      }
  
  
     /**
       * Listener for game menu
       */
      public void onClick(View v) {
          Intent i;
  
          switch (v.getId()){
          case R.id.playBtn :
  
              i = new Intent(this, testcalculator.class);
              startActivity(i);
              break;
  
          case R.id.playBtn2 :
  
              i = new Intent(this, testcalculator2.class);
              startActivity(i);
              break;
  
  
          case R.id.exitBtn :
              finish();
              break;
          }
  
      }
  
     }
  </code></pre>
  
  <p><strong>welcome1.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
  &gt;
  
  &lt;Button
     android:id ="@+id/playBtn"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Calculator"
  /&gt;
  
  &lt;Button
     android:id ="@+id/playBtn2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Calculator2"
  /&gt;
  
  &lt;Button
     android:id ="@+id/exitBtn"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Exit"
  /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>testcalculator.java</strong></p>
  
  <pre><code>    package com.testcalculator;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Spinner;
  import android.widget.AdapterView.OnItemSelectedListener;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class testcalculator extends Activity {
  
  
      double initial_price;
      double discount;
      double final_price; 
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.testcalculator);
          Spinner spinner = (Spinner) findViewById(R.id.spinner1);
          ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(
                this, R.array.discount, android.R.layout.simple_spinner_item);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner.setAdapter(adapter);
          spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
  
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int pos, long id) {
  
                  if (pos==0){
                      discount=10;
                  }
                  else if (pos==1){
                      discount=15;
                  }
                  else if (pos==2){
                      discount=18;
                  }
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                  // TODO Auto-generated method stub
              }   
          });
  
          Button calculate = (Button) findViewById(R.id.calculate);
          calculate.setOnClickListener(new OnClickListener(){
              @Override
              public void onClick(View v) {
                  EditText amount1 = (EditText) findViewById(R.id.amount1);
                  if (amount1.length()&gt;0 ) {
                      initial_price=Double.parseDouble(amount1.getText().toString());
                      TextView final_price_text = (TextView) findViewById(R.id.final_price);
                      final_price=initial_price-(initial_price*discount/100);
                      final_price_text.setText("Final Price : "+final_price);
                  }
                  else {
                      Toast.makeText(getBaseContext(), "Please enter price", Toast.LENGTH_SHORT).show();
                  }
              }
          });       
      }
  }
  </code></pre>
  
  <p><strong>testcalculator.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      &gt;
      &lt;Spinner
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/spinner1"&gt;&lt;/Spinner&gt;
      &lt;TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Enter the price" /&gt;
      &lt;EditText
          android:layout_height="wrap_content"
          android:id="@+id/amount1"
          android:text=""
          android:layout_width="match_parent"
          android:numeric="decimal"&gt;&lt;/EditText&gt;
      &lt;Button
          android:text="Calculate Result"
          android:id="@+id/calculate"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"&gt;&lt;/Button&gt;
      &lt;TextView
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:layout_width="fill_parent"
          android:id="@+id/final_price"&gt;&lt;/TextView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>testcalculator2.java</strong></p>
  
  <pre><code>    package com.testcalculator;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Spinner;
  import android.widget.AdapterView.OnItemSelectedListener;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class testcalculator2 extends Activity {
  
  
      double initial_price;
      double discount2;
      double final_price2;    
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.testcalculator2);
          Spinner spinner = (Spinner) findViewById(R.id.spinner2);
          ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(
                this, R.array.discount2, android.R.layout.simple_spinner_item);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner.setAdapter(adapter);
          spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
  
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int pos, long id) {
  
                  if (pos==0){
                      discount2=20;
                  }
                  else if (pos==1){
                      discount2=25;
                  }
                  else if (pos==2){
                      discount2=28;
                  }
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                  // TODO Auto-generated method stub
              }   
          });
  
          Button calculate2 = (Button) findViewById(R.id.calculate2);
          calculate2.setOnClickListener(new OnClickListener(){
              @Override
              public void onClick(View v) {
                  EditText amount2 = (EditText) findViewById(R.id.amount2);
                  if (amount2.length()&gt;0 ) {
                      initial_price=Double.parseDouble(amount2.getText().toString());
                      TextView final_price_text = (TextView) findViewById(R.id.final_price2);
                      final_price2=initial_price-(initial_price*discount2/100);
                      final_price_text.setText("Final Price : "+final_price2);
                  }
                  else {
                      Toast.makeText(getBaseContext(), "Please enter price", Toast.LENGTH_SHORT).show();
                  }
              }
          });       
      }
  }
  </code></pre>
  
  <p><strong>testcalculator2.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      &gt;
      &lt;Spinner
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/spinner2"&gt;&lt;/Spinner&gt;
      &lt;TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Enter the price" /&gt;
      &lt;EditText
          android:layout_height="wrap_content"
          android:id="@+id/amount2"
          android:text=""
          android:layout_width="match_parent"
          android:numeric="decimal"&gt;&lt;/EditText&gt;
      &lt;Button
          android:text="Calculate Result"
          android:id="@+id/calculate2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"&gt;&lt;/Button&gt;
      &lt;TextView
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:layout_width="fill_parent"
          android:id="@+id/final_price2"&gt;&lt;/TextView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>AndroidManifest.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.testcalculator"
        android:versionCode="1"
        android:versionName="1.0"&gt;
  
  
      &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
          &lt;activity android:name=".welcome"
                    android:label="@string/app_name"&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=".testcalculator" /&gt;
          &lt;activity android:name=".testcalculator2" /&gt;
  
  
  
  
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>strings.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
      &lt;string name="hello"&gt;Hello World, testcalculator!&lt;/string&gt;
      &lt;string name="app_name"&gt;testcalculator&lt;/string&gt;
      &lt;string-array name="discount"&gt;
          &lt;item&gt;10% discount A&lt;/item&gt;
          &lt;item&gt;15% discount B&lt;/item&gt;
          &lt;item&gt;18% discount C&lt;/item&gt;
      &lt;/string-array&gt;
      &lt;string-array name="discount2"&gt;
          &lt;item&gt;20% discount A&lt;/item&gt;
          &lt;item&gt;25% discount B&lt;/item&gt;
          &lt;item&gt;28% discount C&lt;/item&gt;
      &lt;/string-array&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p><strong>main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      &gt;
  &lt;TextView  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/hello"
      /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Please help me!!!</strong></p>