title: When is Context instantiated in android?
body: <p>I have a Dashboard Activity in my android application, and my app also contains an DBHelper class. I noticed that if I were to try to instantiate the DBHelper in the Dashboard Activity(which is the initial activity) it does not work. It tells me that the context is null and gives me a nullpointerexception.</p>
  
  <p>However, this issue does not occur when the DBHelper is instantiated outside the first activity. Why is this? Is context somehow not instantiated in the initial activity of android?</p>
  
  <p>Edit: Would like to add, that I have tried to initialize context in the activity's onCreate method but this is to no avail. </p>
  
  <p>Here's the dashboard fragment: </p>
  
  <pre><code>package azynias.study.Fragments;
  
  import android.app.Activity;
  import android.content.Context;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  import azynias.study.Activities.FrontActivity;
  import azynias.study.DataHandlers.TierDBHandler;
  import azynias.study.R;
  
  
  public class FrontFragment extends Fragment {
      private TextView progItemsDue;
      private TextView progTitle;
  
      private TierDBHandler tierDBHandler = TierDBHandler.getInstance(this.getActivity().getApplicationContext());
  
      private void init(View view) {
          progTitle = (TextView) view.findViewById(R.id.title_progress_dashb_frag);
          progItemsDue = (TextView) view.findViewById(R.id.items_overdue_dashb_frag);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.fragment_front, container, false);
      }
  
  
      @Override
      public void onViewCreated(View view, Bundle savedInstanceState) {
          init(view);
          initProgCard();
      }
  
      public void initProgCard() {
          int due = 5;
  
          progTitle.setText("PROGRESS");
          progItemsDue.setText(due + " items are due today.");
      }
  
      public FrontFragment() {
  
      }
  }
  </code></pre>
  
  <p>And the activity for the dashboard:</p>
  
  <pre><code>package azynias.study.Activities;
  
  import android.content.Context;
  import android.support.v4.app.FragmentTransaction;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  
  import azynias.study.DataHandlers.TierDBHandler;
  import azynias.study.Fragments.FrontFragment;
  import azynias.study.R;
  
  public class FrontActivity extends AppCompatActivity {
  
      private static Context mContext;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_front);
  
          mContext = this.getApplicationContext();
  
          FrontFragment frontFrag = new FrontFragment();
          FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
          ft.replace(R.id.dashboard_material_frag, frontFrag);
  
          ft.commit();
      }
  
      public static Context getContext() {
          //  return instance.getApplicationContext();
          return mContext;
      }
  }
  </code></pre>