Null pointer exception getParent()
<p>I'm getting a null pointer exception. I see that the parent activity is null. I tried using Home. This ( file name is Home.java ) also I tried getApplication() didnt work. Any help is appreaciated. </p>

<pre><code>   code error 


        try {
            Intent previewMessage = new Intent(Home.this, b.class);
            System.out.println("previewMessage is"+previewMessage);

            TabGroupActivity parentActivity = (TabGroupActivity)getParent();
            System.out.println("parentActivity is"+parentActivity);

            parentActivity.startChildActivity("askquestion", previewMessage);
            System.out.println("called asknew now");

        }
        catch(Exception ex){                    
            System.out.println("asknew exception caught "+ex.getMessage());
        }

    full  code Home.java

  package com.sof.android;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
import android.widget.TabHost;
import android.widget.Toast;

public class Home extends TabActivity {



    Button slideHandleButton;
    SlidingDrawer slidingDrawer;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.home);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.home_title);





        //CODE FOR SLIDER -------STARTS HERE---------

        slideHandleButton = (Button) findViewById(R.id.slideHandleButton);
        slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);

        slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {

            @Override
            public void onDrawerOpened() {
                slideHandleButton.setBackgroundResource(R.drawable.openarrow);
            }
        });

        slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {

            @Override
            public void onDrawerClosed() {
                slideHandleButton.setBackgroundResource(R.drawable.closearrow);
            }
        });




        //Logout 

        Button logOut = (Button) this.findViewById(R.id.logout);
        logOut.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {

                System.out.println("Logut out now....");

                AlertDialog.Builder builder = new AlertDialog.Builder(Home.this);
                builder.setMessage("Are you sure you want to Log Out?")
                       .setCancelable(false)
                       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                                finish();
                           }
                       })
                       .setNegativeButton("No", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                           }
                       });
                AlertDialog alert = builder.create();
                alert.show();



            }
        });

        //Ask new question 

        Button askNew = (Button) this.findViewById(R.id.asknew);
        askNew.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                    Message myMessage=new Message();
                    myMessage.obj="ASKNEW";
                    handlerAskNew.sendMessage(myMessage); 


            }
        });


        //CODE FOR SLIDER -------ENDS HERE----------



        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)
        intent = new Intent().setClass(this, a.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("artists").setIndicator("Home",
                          res.getDrawable(R.drawable.a))
                      .setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, b.class);
        spec = tabHost.newTabSpec("albums").setIndicator("Ask",
                          res.getDrawable(R.drawable.b))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, c.class);
        spec = tabHost.newTabSpec("songs").setIndicator("Questions",
                          res.getDrawable(R.drawable.c))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, c.class);
        spec = tabHost.newTabSpec("tutorial").setIndicator("Tutorials",
                          res.getDrawable(R.drawable.d))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, e.class);
        spec = tabHost.newTabSpec("account").setIndicator("Account",
                          res.getDrawable(R.drawable.e))
                      .setContent(intent);
        tabHost.addTab(spec);
        tabHost.setCurrentTab(0);
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
         if (keyCode == KeyEvent.KEYCODE_BACK) {

         //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
             Toast.makeText(getApplicationContext(), "Please Use Log Out.", Toast.LENGTH_LONG).show();   
         return true;

         }

         return super.onKeyDown(keyCode, event);    
    }

     private Handler handlerAskNew = new Handler() {
         @Override
         public void handleMessage(Message msg) {
               String askmsg=(String)msg.obj;
               if(askmsg.equals("ASKNEW")) {

                System.out.println("called asknew now");
                try{
                Intent previewMessage = new Intent(Home.this, b.class);
                System.out.println("previewMessage is"+previewMessage);

                TabGroupActivity parentActivity = (TabGroupActivity)getParent();
                System.out.println("called asknew now");

                parentActivity.startChildActivity("askquestion", previewMessage);
                System.out.println("called asknew now");

                }catch(Exception ex){

                    System.out.println("asknew exception caught "+ex.getMessage());
                }
                //Intent intent = new Intent(getApplicationContext(), b.class);
                   //intent.putExtra("LoginMessage", "Logged Out");
                //startActivity(intent); 
                   removeDialog(0);
               }
         }
     }; 

}
</code></pre>
