title: how we can do android oncreate methods object creation in android testing indepentlly
body: <p>I am doing android testing of Layout of one application.After running that application it is giving error "Java Nullpointer exception" due to failing of Object creation.That object is created in Oncreate method of activity.
      IS THAT Oncreate method is not calling by Testcases?Please help me for resolving this issue.</p>
  
  <p>This is whole Activity's code:-</p>
  
  <pre><code> package com.example.app;
  
  import android.app.ActionBar.LayoutParams;
  import android.content.Intent;
  import android.graphics.Color;
  import android.os.Bundle;
  import android.support.v7.app.ActionBarActivity;
  import android.util.TypedValue;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.TableLayout;
  import android.widget.TableRow;
  import android.widget.TextView;
  
  public class Appointment extends ActionBarActivity {
  
      Button enternewRecord;
      TableLayout  appointment_table;
       Button homepage;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.appointment);
           appointment_table=(TableLayout)findViewById(R.id.appointment_table);
             // fillCountryTable();
          enternewRecord=(Button)findViewById(R.id.button1);
          homepage=(Button)findViewById(R.id.button2);
          enternewRecord.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
              Intent i=new Intent(Appointment.this,AddAppointment.class);
              startActivity(i);
              }
          });
  
  homepage.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
              Intent i=new Intent(Appointment.this,TabBar.class);
              startActivity(i);
              }
          });
      }
       void fillCountryTable() {
  
              TableRow row;
              TextView t1, t2;
              AppointmentList appointListObj=new AppointmentList();
              //appointListObj.setAppointmentData();
              //Converting to dip unit
              int dip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                      (float) 1, getResources().getDisplayMetrics());
  
              for (int current = 0; current &lt; appointListObj.getDate().length; current++) {
                  row = new TableRow(this);
  
                  t1 = new TextView(this);
                  t1.setTextColor(Color.parseColor("#6B4724"));
                  t2 = new TextView(this);
                  t2.setTextColor(Color.parseColor("#6B4724"));
  
                  t1.setText(appointListObj.getPhysicianName()[current]);
                  t2.setText(appointListObj.getDate()[current]);
  
                  t1.setTypeface(null, 1);
                  t2.setTypeface(null, 1);
  
                  t1.setTextSize(15);
                  t2.setTextSize(15);
  
                  t1.setWidth(50 * dip);
                  t2.setWidth(50 * dip);
                  t1.setPadding(0*dip, 0, 0, 0);
                  //t2.setPadding(0*dip, 0, 0, 0);
                  row.addView(t1);
                  row.addView(t2);
  
                  appointment_table.addView(row, new TableLayout.LayoutParams(
                          LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  
              }
          }
      }
  
  
  This is test code:-
  
  
  
  package com.example.androidgui.testingfun.tests;
  import com.example.app.Appointment;
  import com.example.app.R;
  import com.example.app.Weight;
  import android.annotation.SuppressLint;
  import android.test.ActivityInstrumentationTestCase2;
  import android.test.ViewAsserts;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.WindowManager;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  
  
  @SuppressLint("NewApi")
  public class AppointmentTest
  extends ActivityInstrumentationTestCase2&lt;Appointment&gt; {
  
      public AppointmentTest() {
          super(Appointment.class);
          // TODO Auto-generated constructor stub
      }
  
  
      private Appointment AppointmentTestActivity;
      private Button submitButton;
  
      private TextView tv_11;
      private TextView tv_12;
      private int textViewCnt=0;
  
      private int buttonCnt=0;
  
      @SuppressLint("NewApi")
      @Override
      protected void setUp() throws Exception {
          super.setUp();
          AppointmentTestActivity = getActivity();
          submitButton =
                  (Button) AppointmentTestActivity
                  .findViewById(com.example.app.R.id.button2);
          tv_11 = (TextView) AppointmentTestActivity.findViewById(R.id.tv_11);
          tv_12 = (TextView) AppointmentTestActivity.findViewById(R.id.tv_12);
  
  
      }
  
  //Activity Created Or not
      public void testActivity() {
          assertNotNull("AppointmentTestActivity is null", AppointmentTestActivity);
  
  
      }
    public void testButton(){
  
     //submitButton Created or not      
    assertNotNull("submitButton is null",submitButton);
  
    //Text of submitButton
    assertEquals(submitButton.getText().toString(),"HomePage");
  
    //Test submitButton is visible Or Not
    ViewAsserts.assertOnScreen(submitButton.getRootView(),submitButton);
  
  
    //submitButton Button Clickable or not
    assertNotNull("submitButton is not clickable",submitButton.isClickable());
  
  //submitButton Button Enable or not
     assertNotNull("submitButton is not enabled",submitButton.isEnabled());
  
       if(submitButton.isClickable())
         {
          buttonCnt++;
         }
  
  
     //Testing of submitButton Layout Parameter
    ViewGroup.LayoutParams layoutParams =
            submitButton.getLayoutParams();
    assertNotNull(layoutParams);
    assertEquals(layoutParams.width, WindowManager.LayoutParams.WRAP_CONTENT);
    assertEquals(layoutParams.height, WindowManager.LayoutParams.WRAP_CONTENT);
  
  //Count of the Buttons Present
    assertEquals(buttonCnt, 1);
  
  
  
   }
  
  
    public void testTextView(){
  
        //TextView Created Or not
        assertNotNull("tv_11 is null",tv_11);
  
  
        //Text of TextView
        assertEquals("PhysicianName",tv_11.getText().toString());
  
        //Visibility of TextView
        ViewAsserts.assertOnScreen(tv_11.getRootView(),tv_11);
  
  
        //textView Enable or not
        assertNotNull("tv_11 is not enabled",tv_11.isEnabled());
  
      //TextViews Layout
        ViewGroup.LayoutParams layoutParams =
                 tv_11.getLayoutParams();
        assertNotNull(layoutParams);
  
        assertEquals(layoutParams.height, WindowManager.LayoutParams.WRAP_CONTENT);
  
  
  
      //TextView Created Or not
        assertNotNull("tv_12 is null",tv_12);
  
  
        //Text of TextView
        assertEquals("DateOfAppointment",tv_12.getText().toString());
  
        //Visibility of TextView
        ViewAsserts.assertOnScreen(tv_12.getRootView(),tv_12);
  
      //TextViews Layout
         layoutParams =
                 tv_12.getLayoutParams();
        assertNotNull(layoutParams);
  
        assertEquals(layoutParams.height, WindowManager.LayoutParams.WRAP_CONTENT);
  
  
  
  
  
        assertNotNull("tv_12 is not enabled",tv_12.isEnabled());
  
  
        if( tv_11.isEnabled())
        {
            textViewCnt++;
        }
  
        if(tv_12.isEnabled())
        {
            textViewCnt++;
        }
  
        //Count of the textViewCnts Present
        assertEquals(textViewCnt, 2);
  
     }
  }
  </code></pre>
  
  <p>Please Help....</p>