title: Android Null object Reference
body: <p>Okay so I have two activities and I am trying to open the activity Insert on a Button click.
  But it gives a message Unfortunately activity has stopped unexpectedly or whatever..</p>
  
  <p>Part of code from the Main Activity where button is calling intent:</p>
  
  <pre><code>//The intent typed earlier in the activity
   Intent myIntent = new Intent(MainActivity.this, Insert.class);
  
  private OnClickListener onClick() {
      return new OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
              switch (v.getId()) {
                  case R.id.addcolumnbutton:
                      if(value==k||value==10)
                      {
                          Toast.makeText(getApplicationContext(), "Maximum number of Columns created",
                                  Toast.LENGTH_SHORT).show();
                      }
                      else {
                          k++;
                          mLayout.addView(createNewLayout());
                      }
                      break;
                  case R.id.createtablebutton:
                      if(value==k) {
  
                         MainActivity.this.startActivity(myIntent);
  
                      }
                      else
                      {
                          Toast.makeText(getApplicationContext(), "Incorrect number of Columns created",
                                  Toast.LENGTH_SHORT).show();
  
                      }
                      break;
              }
          }
  
  
      };
  }
  </code></pre>
  
  <p>My LogCat Here:</p>
  
  <pre><code>    03-02 17:21:34.342  12789-12789/com.cambiopune.tosdatabase D/AndroidRuntime﹕       Shutting down VM
    03-02 17:21:34.345  12789-12789/com.cambiopune.tosdatabase E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: com.cambiopune.tosdatabase, PID: 12789
  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.cambiopune.tosdatabase/com.cambiopune.tosdatabase.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
          at android.app.ActivityThread.access$800(ActivityThread.java:144)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5221)
          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:899)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
             at   android.content.ContextWrapper.getPackageName(ContextWrapper.java:131)
           at android.content.ComponentName.&lt;init&gt;(ComponentName.java:77)
           at android.content.Intent.&lt;init&gt;(Intent.java:3996)
           at com.cambiopune.tosdatabase.MainActivity.&lt;init&gt;(MainActivity.java:34)
          at java.lang.reflect.Constructor.newInstance(Native Method)
          at java.lang.Class.newInstance(Class.java:1572)
          at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)  
  </code></pre>
  
  <p>           </p>