title: Calling activity to another activity using intent failed
body: <p>I have a class called "Datetime", I want to call Datetime's activity into my MainActivity using intent. </p>
  
  <p>This is what I did </p>
  
  <pre><code>public void onClick(View view) {
  
          Intent i = new Intent(this, Datetime.class);
          startActivity(i);
  </code></pre>
  
  <p>}</p>
  
  <p>and I also updated my manifest:</p>
  
  <pre><code> &lt;activity
                android:name=".Datetime" &gt;
   &lt;/activity&gt;
  </code></pre>
  
  <p>but it doesn't work. What is wrong with my code?</p>
  
  <p>Just in case, you want to refer. The following is my Datetime class:</p>
  
  <pre><code>public class Datetime extends Activity {
  
      static final int DATE_DIALOG_ID = 1;
      static final int TIME_DIALOG_ID = 2;
  
      private Button pickDate;
      private int year, month, day;
  
      private Button pickTime;
      private int hours, min;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.create_layout);
  
  
          pickDate = (Button)findViewById(R.id.date_button);
  
          pickDate.setOnClickListener( new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  showDialog(DATE_DIALOG_ID);
              }
  
          });
  
          final Calendar cal = Calendar.getInstance();
          year = cal.get(Calendar.YEAR);
          month = cal.get(Calendar.MONTH);
          day = cal.get(Calendar.DAY_OF_MONTH);
  
          updateDate();
  
  
          pickTime = (Button)findViewById(R.id.time_button);
  
          pickTime.setOnClickListener( new OnClickListener () {
  
              @Override
              public void onClick(View v) {
                  showDialog(TIME_DIALOG_ID);
  
              }
  
          });
  
          hours = cal.get(Calendar.HOUR);
          min = cal.get(Calendar.MINUTE);
  
          updateTime();
      }
  
      private void updateTime() {
          pickTime.setText(new StringBuilder().append(hours).append(':')
                  .append(min));
  
      }
  
      private void updateDate() {
          pickDate.setText(new StringBuilder().append(day).append('-')
                  .append(month + 1).append('-').append(year));
  
      }
  
      private DatePickerDialog.OnDateSetListener dateListener = 
          new DatePickerDialog.OnDateSetListener() {
  
              @Override
              public void onDateSet(DatePicker view, int yr, int monthOfYear,
                      int dayOfMonth) {
                  year = yr;
                  month = monthOfYear;
                  day = dayOfMonth;
                  updateDate();
              }
      };
  
      private TimePickerDialog.OnTimeSetListener timeListener = 
          new TimePickerDialog.OnTimeSetListener() {
  
              @Override
              public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                  hours = hourOfDay;
                  min = minute;
                  updateTime();
              }
  
      };
      protected Dialog onCreateDialog(int id){
          switch(id) {
          case DATE_DIALOG_ID:
              return new DatePickerDialog(this, dateListener, year, month, day);
          case TIME_DIALOG_ID:
              return new TimePickerDialog(this, timeListener, hours, min, false);
          }
          return null;
  
      }
  }
  </code></pre>
  
  <p>logcat:</p>
  
  <pre><code>07-03 16:36:37.394: E/Dynamiclayout(1282): java.lang.IndexOutOfBoundsException: charAt: 0 &gt;= length 0
  07-03 16:36:37.394: E/Dynamiclayout(1282): java.lang.IndexOutOfBoundsException: charAt: 0 &gt;= length 0
  07-03 16:36:37.424: E/SpannableStringBuilder(1282): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
  07-03 16:36:37.424: E/SpannableStringBuilder(1282): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
  07-03 16:36:37.424: E/SpannableStringBuilder(1282): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
  07-03 16:36:37.424: E/SpannableStringBuilder(1282): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
  07-03 16:36:42.189: D/GestureDetector(1282): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 3 mFalseSizeCnt:0
  </code></pre>
  
  <p>As requested, my MainActivity class:</p>
  
  <pre><code>public class MainActivity extends TabActivity { 
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Resources res = getResources(); // Resource object to get Drawables
          TabHost tabHost = getTabHost();  // The activity TabHost
          TabHost.TabSpec spec;  // Resusable TabSpec for each tab
          Intent intent;  // Reusable Intent for each tab
  
          // Create an Intent to launch an Activity for the tab (to be reused)
  
          // Initialize a TabSpec for each tab and add it to the TabHost
          intent = new Intent().setClass(this, ViewTab.class);
  
          spec = tabHost.newTabSpec("View").setIndicator("View",
                            res.getDrawable(R.drawable.ic_tab_view))
                        .setContent(intent);
          tabHost.addTab(spec);
  
  
          intent = new Intent().setClass(this, CreateTab.class);
  
          // Do the same for the other tabs
          spec = tabHost.newTabSpec("Create").setIndicator("Create",
                            res.getDrawable(R.drawable.ic_tab_create))
                        .setContent(intent);
          tabHost.addTab(spec);
  
  
  
          tabHost.setCurrentTab(2);
  
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          super.onCreateOptionsMenu(menu);
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.main, menu);
          return true;
      }
  
  
      @Override 
      public boolean onOptionsItemSelected(MenuItem item) {
          switch(item.getItemId()) {
          case R.id.menu_about:
              startActivity(new Intent(this,About.class));
              return true;
          }
  
          return false;
      }
  
  
      public void onClick(View view) {
  
          Intent i = new Intent(this, Datetime.class);
          startActivity(i);
  
  
          }
  
  
  }
  </code></pre>