title: Unable to launch my android apps. "Shutting down VM" Error
body: <p>I'm currently using Eclipse to do a simple interface that allow user to insert their name then will intent to other page.</p>
  
  <p>However I'm stuck now because some strange problem. Although it shows that "Shutting Down VM" but I doubt that's the main reason.</p>
  
  <p>here's my code</p>
  
  <pre><code>    package com.ytl.test;
  
      import android.app.Activity;
      import android.app.AlertDialog;
      import android.content.DialogInterface;
      import android.content.Intent;
      import android.os.Bundle;
      import android.view.Menu;
      import android.view.View;
      import android.view.View.OnClickListener;
      import android.widget.Button;
      import android.widget.EditText;
      import android.widget.LinearLayout;
      import android.widget.TextView;
      import com.ytl.test.MainActivity;
  
  public class MainActivity extends Activity {
  
  
      private TextView tvName;
      private EditText Name;
      private Button btnConfirm = new Button(this) ;
      private String stringName = new String();
      AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          LinearLayout layout = new LinearLayout(this);
          layout.setOrientation(LinearLayout.VERTICAL);
  
          tvName = new TextView(this);
          tvName.setText("Please enter your name: ");
          Name = new EditText(this);
          Name.setHint("Your Name");
          btnConfirm = new Button(this);
          btnConfirm.setText("Confirm");
  
          btnConfirm.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  stringName = Name.getText().toString();
                  if(stringName.isEmpty()){
                      alertDialog.setTitle("Error");
                      alertDialog.setMessage("Name cannot be left empty. Please insert your name");
                      alertDialog.setCancelable(false);
                      alertDialog.setPositiveButton("Ok",
                              new DialogInterface.OnClickListener() {
  
                                  @Override
                                  public void onClick(DialogInterface dialog,
                                          int which) { 
                                      Name.setFocusable(true);
                                      Name.setFocusableInTouchMode(true);
                                      Name.requestFocus();
                                  }
                              });
  
                      alertDialog.show();
                      Name.requestFocus();
                  }
                  else{
                      StringBuffer sbName = new StringBuffer();
                      sbName.append(stringName);
                      Intent intNext = new Intent(MainActivity.this,MainPage.class);
                      intNext.putExtra("Name",stringName.toString()); // i.putExtra only allow for String
  
                      startActivity(intNext);
                  }
  
              }
          });
  
          layout.addView(tvName);
          layout.addView(Name);
          layout.addView(btnConfirm);
          setContentView(layout);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p>and here's my logcat</p>
  
  <pre><code>03-15 14:37:38.143: D/AndroidRuntime(7217): Shutting down VM
  03-15 14:37:38.143: W/dalvikvm(7217): threadid=1: thread exiting with uncaught exception (group=0x55e04b20)
  03-15 14:37:38.143: D/AndroidRuntime(7217): procName from cmdline: com.ytl.test
  03-15 14:37:38.143: E/AndroidRuntime(7217): in writeCrashedAppName, pkgName :com.ytl.test
  03-15 14:37:38.143: D/AndroidRuntime(7217): file written successfully with content: com.ytl.test StringBuffer : ;com.ytl.test
  03-15 14:37:38.153: E/AndroidRuntime(7217): FATAL EXCEPTION: main
  03-15 14:37:38.153: E/AndroidRuntime(7217): Process: com.ytl.test, PID: 7217
  03-15 14:37:38.153: E/AndroidRuntime(7217): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ytl.test/com.ytl.test.MainActivity}: java.lang.NullPointerException
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.os.Handler.dispatchMessage(Handler.java:102)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.os.Looper.loop(Looper.java:136)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.app.ActivityThread.main(ActivityThread.java:5021)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at java.lang.reflect.Method.invokeNative(Native Method)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at java.lang.reflect.Method.invoke(Method.java:515)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at dalvik.system.NativeStart.main(Native Method)
  03-15 14:37:38.153: E/AndroidRuntime(7217): Caused by: java.lang.NullPointerException
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.content.ContextWrapper.getResources(ContextWrapper.java:89)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:78)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.view.View.&lt;init&gt;(View.java:3443)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.view.View.&lt;init&gt;(View.java:3510)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.widget.TextView.&lt;init&gt;(TextView.java:623)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.widget.Button.&lt;init&gt;(Button.java:107)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.widget.Button.&lt;init&gt;(Button.java:103)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.widget.Button.&lt;init&gt;(Button.java:99)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at com.ytl.test.MainActivity.&lt;init&gt;(MainActivity.java:22)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at java.lang.Class.newInstanceImpl(Native Method)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at java.lang.Class.newInstance(Class.java:1208)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.app.Instrumentation.newActivity(Instrumentation.java:1064)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
  03-15 14:37:38.153: E/AndroidRuntime(7217):     ... 11 more
  03-15 14:37:38.213: D/AndroidRuntime(7230): Shutting down VM
  03-15 14:37:38.213: W/dalvikvm(7230): threadid=1: thread exiting with uncaught exception (group=0x55e04b20)
  </code></pre>
  
  <p>Thanks in advance for the help</p>
  
  <p>Update of my XML file</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.ytl.test"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="19"
          android:targetSdkVersion="21" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &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;service android:name=".BackgroundService" &gt;
          &lt;/service&gt;
  
          &lt;activity
              android:name=".MainPage"
              android:label="@string/title_activity_main_page" &gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>