Creating objects in superclass
<p>I have one superclass in my android project that inherits from activity and implements all the  necessary interfaces. I then have three different activities that inherit from this superclass. I initialize the variables in the superclass from all the subclasses once the activities are created. Superclass method:</p>

<pre><code>protected void initiateVariables(Context c){
    dm = new DisplayMetrics();
    toasty = new Toast(c);
    customBuilder = new MyDialog.Builder(c);
    customDialog = new Dialog(c);
    customProgress = new MyProgressDialog(c);
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    screenWidth = dm.widthPixels;
    screenHeight = dm.heightPixels;
}
</code></pre>

<p>From the subclasses I do:</p>

<pre><code>protected void initiateVariables(Context c) {
    super.initiateVariables(c);
    bFavorite = (Button) findViewById(R.id.bFavorite);
    bSetting = (Button) findViewById(R.id.bSettings);
    bCompass = (Button) findViewById(R.id.bCompass);
    bDeparture = (Button) findViewById(R.id.bDeparture);
    bInfo = (Button) findViewById(R.id.bInfo);
    bBack = (Button) findViewById(R.id.bBack);
    bDeparture2 = (Button) findViewById(R.id.bForward);
    bAdd = (Button) findViewById(R.id.bAdd);
    tvHeader = (TextView) findViewById(R.id.tvHeaderText);
    flipp = (ViewFlipper) findViewById(R.id.viewFlipper);
    colorBackground = (RelativeLayout) findViewById(R.id.homeBackground);
    dbList = (ListView) findViewById(R.id.dbList); }
</code></pre>

<p>onCreate method in my subclasses:</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);
    initiateVariables(this);
}
</code></pre>

<p>When I try to use any object that has been initialized in the superclass I get a nullpointerexception. Could anyone explain to me why this is?</p>
