title: Android app hangs when referencing the back button on Secondary screen
body: <p>I have a small app that when button presses navigates when moving from main screen to next screen this works fine, but when I added a button on the next page (to go back) it breaks.</p>
  
  <p>Fun.java</p>
  
  <pre><code>package com.forcetechnology.OptusApp;
  
  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 Fun extends Activity {
  OnClickListener backListener;
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.fun);
  
      Button backButtonf = (Button)findViewById(com.forcetechnology.OptusApp.R.id.backtoMainf);
      backListener = new OnClickListener()
      {           
          public void onClick(View v) 
          {        
           Intent i = new Intent();
           i.setClassName("com.forcetechnology.OptusApp", "com.forcetechnology.OptusApp.OptusAppMain");
                  startActivity(i);           
          }
      };
      backButtonf.setOnClickListener(backListener);
  
     }
  
  }
  </code></pre>
  
  <p>Fun.Xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" &gt;
  
  
  
  
  &lt;ImageButton
      android:id="@+id/backtoMainf"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/val5" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Main.xml
      
  </p>
  
  <pre><code>&lt;ImageButton
      android:id="@+id/funbutton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:background="@drawable/val5"
      android:src="@drawable/val5" /&gt;
  
  
  
  &lt;ImageButton
      android:id="@+id/executionbutton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@+id/funbutton"
      android:layout_alignParentRight="true"
      android:background="@drawable/val2"
      android:src="@drawable/val2" /&gt;
  
  
  
  &lt;ImageButton
      android:id="@+id/performancebutton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/executionbutton"
      android:layout_toLeftOf="@+id/funbutton"
      android:background="@drawable/val3"
      android:src="@drawable/val4" /&gt;
  
  
  
  &lt;ImageButton
      android:id="@+id/innovationbutton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignBottom="@+id/executionbutton"
      android:layout_alignParentLeft="true"
      android:background="@drawable/val3"
      android:src="@drawable/val3" /&gt;
  
  
  
  &lt;ImageButton
      android:id="@+id/peoplebutton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@+id/innovationbutton"
      android:layout_toLeftOf="@+id/executionbutton"
      android:background="@drawable/val1"
      android:src="@drawable/val1" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>OPtusAppMain.java</p>
  
  <pre><code>    package com.forcetechnology.OptusApp;
  
  import android.R;
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.ImageButton;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class OptusAppMain extends Activity 
  {
      OnClickListener funListener,executionListener,innovationListener,peopleListener,performanceListener;;
      TextView testView;
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(com.forcetechnology.OptusApp.R.layout.main);
          ImageButton funButton = (ImageButton)findViewById(com.forcetechnology.OptusApp.R.id.funbutton);
          ImageButton executionButton = (ImageButton)findViewById(com.forcetechnology.OptusApp.R.id.executionbutton);
          ImageButton innovationButton = (ImageButton)findViewById(com.forcetechnology.OptusApp.R.id.innovationbutton);
          ImageButton peopleButton = (ImageButton)findViewById(com.forcetechnology.OptusApp.R.id.peoplebutton);
          ImageButton performanceButton = (ImageButton)findViewById(com.forcetechnology.OptusApp.R.id.performancebutton);
  
  
          funListener = new OnClickListener()
          {           
              public void onClick(View v) 
              {        
                   Intent i = new Intent();
                      i.setClassName("com.forcetechnology.OptusApp", "com.forcetechnology.OptusApp.Fun");
                      startActivity(i);           
              }
          };
          executionListener = new OnClickListener()
          {           
              public void onClick(View v) 
              {        
                   Intent i = new Intent();
                   i.setClassName("com.forcetechnology.OptusApp", "com.forcetechnology.OptusApp.Execution");
                      startActivity(i);          
              }
          };
          innovationListener = new OnClickListener()
          {           
              public void onClick(View v) 
              {        
                   Intent i = new Intent();
                   i.setClassName("com.forcetechnology.OptusApp", "com.forcetechnology.OptusApp.Innovation");
                      startActivity(i);           
              }
          };
          peopleListener = new OnClickListener()
          {           
              public void onClick(View v) 
              {        
                   Intent i = new Intent();
                   i.setClassName("com.forcetechnology.OptusApp", "com.forcetechnology.OptusApp.People");
                      startActivity(i);           
              }
          };
          performanceListener = new OnClickListener()
          {           
              public void onClick(View v) 
              {        
                   Intent i = new Intent();
                   i.setClassName("com.forcetechnology.OptusApp", "com.forcetechnology.OptusApp.Performance");
                      startActivity(i);         
              }
          };
          funButton.setOnClickListener(funListener);
          executionButton.setOnClickListener(executionListener);
          innovationButton.setOnClickListener(innovationListener);
          peopleButton.setOnClickListener(peopleListener);
          performanceButton.setOnClickListener(performanceListener);
      }
  
  
  
  
  }
  </code></pre>
  
  <p>Edit: I have traced the error to this line Button backButtonf = (Button)findViewById(com.forcetechnology.OptusApp.R.id.backtoMainf); in fun.java.</p>