title: Android Start Activity from another class
body: <p>Hi guys I am new in android and I am trying  to create a bottom menu which appear in all activities. So I created the menu in xml layout and attached it to the layout of my application using</p>
  
  <pre><code> &lt;include android:layout_width="fill_parent" layout="@layout/menu"
          android:layout_height="wrap_content" /&gt;
  </code></pre>
  
  <p>Now i want to link  this layout to a class which will contain starting activities and change the color of the active menu ...</p>
  
  <p>The problem is when I open an activity using Intent in other class <code>(menu.class)</code> I got <code>NullPointerException</code> </p>
  
  <p>I have added the activities in AndroidManifest. I'm able to start the new activity in main class (MainActivity.class) but when i try to do it in menu class I get NullPointerException.</p>
  
  <p>this is my code :</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          menu m = new menu((LinearLayout) findViewById(R.id.mn1),(LinearLayout) findViewById(R.id.mn2),
                  (LinearLayout) findViewById(R.id.mn3),(LinearLayout) findViewById(R.id.mn4));
          m.btmmenu(new Intent(this, time.class));
      } }
  </code></pre>
  
  <p>the menu class :</p>
  
  <pre><code>public class menu extends Activity {
      LinearLayout mn1,mn2,mn3,mn4;
      public menu(LinearLayout mn1,LinearLayout mn2,LinearLayout mn3,LinearLayout mn4) {
          this.mn1=mn1;
          this.mn2=mn2;
          this.mn3=mn3;
          this.mn4=mn4;
      }
      public void btmmenu(final Intent i) {
          mn4.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                    startActivity(i);
              }
          });
      } }
  </code></pre>
  
  <p>i tried to send the Intent in the constructor i also tried to create the intent in the menu class but i always get NullPointerException</p>
  
  <pre><code>02-02 14:12:21.511    3319-3319/com.android.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.NullPointerException
              at android.app.Activity.startActivityForResult(Activity.java:3429)
              at android.app.Activity.startActivityForResult(Activity.java:3390)
              at android.app.Activity.startActivity(Activity.java:3600)
              at android.app.Activity.startActivity(Activity.java:3568)
              at com.xochn.okanime.menu$1.onClick(menu.java:21)
              at android.view.View.performClick(View.java:4191)
              at android.view.View$PerformClick.run(View.java:17229)
              at android.os.Handler.handleCallback(Handler.java:615)
              at android.os.Handler.dispatchMessage(Handler.java:92)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:4960)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
              at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>anyone know how to do this ?</p>
  
  <p>thanks.</p>