title: null pointer exception in android
body: <pre><code>public void but(View v){
    //Toast.makeText(getApplicationContext(), "nai", Toast.LENGTH_SHORT).show();
    Intent intent = new Intent(MainActivity.this,Messaging.class);
    startActivity(intent);
  }
  </code></pre>
  
  <p>I want to open another activity from my main activity. Another class is Messaging. It has another layout named <code>messaging_layout</code>. In the code there are no error but after run this code, when I press this button program crashes and throws a NullPointerException.</p>
  
  <p>If I omit</p>
  
  <pre><code>Intent intent = new Intent(MainActivity.this,Messaging.class);
  startActivity(intent);
  </code></pre>
  
  <p>the button will work properly.</p>