title: Link two layouts in android
body: <p>I am trying to link my two Android layout and make the process.</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                          .setAction("Action", null).show();
              }
          });
  
  
  
      }
  
      public void open(View view){
          AlertDialog.Builder alb=new AlertDialog.Builder(this);
          alb.setMessage("Are You Sure Do You Want This");
          alb.setPositiveButton("yes", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
             Toast.makeText(MainActivity.this,"You Clicked Yes Button",Toast.LENGTH_LONG).show();
              }
          });
  
          alb.setNegativeButton("NO", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  Toast.makeText(MainActivity.this,"You Clicked Yes Button",Toast.LENGTH_LONG).show();
                  //finish();
              }
          });
          AlertDialog al=alb.create();
          al.show();
      }
  
  
      public void clockwise(View view){
          ImageView iv=(ImageView) findViewById(R.id.imageView);
          Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.myanimation);
          iv.startAnimation(animation);
      }
      public void zoom(View view){
  ImageView iv=(ImageView) findViewById(R.id.imageView);
          Animation animation=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.clockwise);
          iv.startAnimation(animation);
      }
  
      public void fade(View view){
          ImageView iv=(ImageView) findViewById(R.id.imageView);
          Animation animation=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade);
          iv.startAnimation(animation);
      }
  
      public void blink(View view){
          ImageView iv=(ImageView)findViewById(R.id.imageView);
          Animation animation=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.blink);
          iv.startAnimation(animation);
      }
  
      public void move(View view){
          ImageView iv=(ImageView)findViewById(R.id.imageView);
          Animation animation=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.move);
          iv.startAnimation(animation);
      }
  
      public void slide(View view){
          ImageView iv=(ImageView)findViewById(R.id.imageView);
          Animation animation=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide);
          iv.startAnimation(animation);
      }
  
  
  
  
  
  
  public void next(View v){
     // setContentView(R.layout.recording);
     Intent inent = new Intent(this, RecordActivity.class);
  
    startActivity(inent);
  }
  
      @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_main, 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><strong>RecordActivity.java</strong></p>
  
  <pre><code>public class RecordActivity extends Activity {
      private MediaRecorder mr;
      Button play,record,stop;
      private String outputFile=null;
      @Override
     public void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);
          setContentView(R.layout.recording);
  
          play=(Button)findViewById(R.id.button3);
          stop=(Button)findViewById(R.id.button2);
          record=(Button)findViewById(R.id.button);
          stop.setEnabled(false);
          play.setEnabled(false);
  
          outputFile= Environment.getExternalStorageDirectory().getAbsolutePath()+"/recording.3gp";
          mr=new MediaRecorder();
          mr.setAudioSource(MediaRecorder.AudioSource.MIC);
          mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
          mr.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
          mr.setOutputFile(outputFile);
  
      }
  
  
      public void Record(View v){
          try{
              mr.prepare();
              mr.start();
          }
          catch (Exception e){
              e.printStackTrace();
          }
          record.setEnabled(false);
          stop.setEnabled(true);
  
  
      }
  
  
      public void stop(View v){
          mr.stop();
          mr.release();
          mr=null;
          stop.setEnabled(false);
          play.setEnabled(true);
          Toast.makeText(getApplicationContext(),"AudioRecorded Sucessfully",Toast.LENGTH_LONG);
  
      }
  
      public void play(View v){
          MediaPlayer mp=new MediaPlayer();
          try{
              mp.setDataSource(outputFile);
              mp.prepare();
          }
          catch (Exception e){
              e.printStackTrace();
          }
          mp.start();
          Toast.makeText(getApplicationContext(),"Playing Audio",Toast.LENGTH_LONG);
      }
  
  }
  </code></pre>
  
  <p><strong>content_main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:context="com.example.admin.alertapplication.MainActivity"&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Alert Dialog"
          android:id="@+id/textView"
          android:textSize="35dp"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Raptor"
          android:id="@+id/textView2"
          android:textColor="#da644860"
          android:textSize="35dp"
          android:layout_below="@+id/textView"
          android:layout_centerHorizontal="true" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/imageView"
          android:src="@drawable/logo"
          android:layout_below="@+id/textView2"
          android:layout_alignLeft="@+id/textView"
          android:layout_alignStart="@+id/textView"
          android:layout_alignRight="@+id/button2"
          android:layout_alignEnd="@+id/button2" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="zoom"
          android:id="@+id/button"
          android:layout_below="@+id/imageView"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginTop="40dp"
          android:onClick="clockwise"/&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="clockwise"
          android:id="@+id/button2"
          android:layout_alignTop="@+id/button"
          android:layout_centerHorizontal="true"
          android:onClick="zoom"/&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="fade"
          android:id="@+id/button3"
          android:layout_alignTop="@+id/button2"
          android:layout_alignParentRight="true"
          android:layout_alignParentEnd="true"
          android:onClick="fade"/&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="blink"
          android:onClick="blink"
          android:id="@+id/button4"
          android:layout_below="@+id/button"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="move"
          android:onClick="move"
          android:id="@+id/button5"
          android:layout_below="@+id/button2"
          android:layout_alignRight="@+id/button2"
          android:layout_alignEnd="@+id/button2"
          android:layout_alignLeft="@+id/button2"
          android:layout_alignStart="@+id/button2" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="slide"
          android:onClick="slide"
          android:id="@+id/button6"
          android:layout_below="@+id/button3"
          android:layout_toRightOf="@+id/textView"
          android:layout_toEndOf="@+id/textView" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Next"
          android:onClick="next"
          android:id="@+id/button61"
          android:layout_below="@+id/button4"
          android:layout_alignRight="@+id/button4"
          android:layout_alignEnd="@+id/button4" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>recording.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="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"
      android:weightSum="1"&gt;
  
      &lt;TextView
          android:layout_width="234dp"
          android:layout_height="112dp"
          android:text="Android Audio Recording"
          android:id="@+id/textView3"
          android:layout_gravity="center_horizontal"
  
          android:textSize="30dp"
          android:textColor="#d50c0c"
          android:layout_weight="0.01" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="86dp"
          android:id="@+id/imageView2"
          android:src="@drawable/logo"
          android:layout_gravity="center_horizontal"
          /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Record"
          android:id="@+id/button7"
          android:layout_below="@+id/imageView2"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginTop="59dp"
          android:onClick="Record"
          /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Stop"
          android:id="@+id/button8"
          android:layout_alignTop="@+id/button"
          android:layout_centerHorizontal="true"
          android:layout_gravity="center_horizontal"
          android:onClick="stop"
          /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="play"
          android:id="@+id/button9"
          android:layout_alignTop="@+id/button8"
          android:layout_alignRight="@+id/textView3"
          android:layout_alignEnd="@+id/textView3"
          android:layout_gravity="right"
          android:onClick="play"
          /&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.example.admin.alertapplication"&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.RECORD_AUDIO"/&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme.NoActionBar"&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=".RecordActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme.NoActionBar"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.VIEW" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <blockquote>
    <p><strong>stack trace</strong>
    04-22 14:24:09.415 4470-4470/com.example.admin.alertapplication E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                      Process: com.example.admin.alertapplication, PID: 4470
                                                                                      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.admin.alertapplication/com.example.admin.alertapplication.RecordActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setEnabled(boolean)' on a null object reference
                                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
                                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                                                                                          at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                                                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                          at android.os.Looper.loop(Looper.java:135)
                                                                                          at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                                                       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setEnabled(boolean)' on a null object reference
                                                                                          at com.example.admin.alertapplication.RecordActivity.onCreate(RecordActivity.java:27)
                                                                                          at android.app.Activity.performCreate(Activity.java:5990)
                                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
                                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                                          at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                          at android.os.Looper.loop(Looper.java:135) 
                                                                                          at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                                          at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) </p>
  </blockquote>
  
  <p>I am using the above code to for linking the two layouts when next button was clicked <strong>next()</strong> function will be called after that <strong>Unfortunately application has stopped</strong> why it's happening can any one help me to fix this </p>