Caused by: java.lang.ClassCastException
===

Description:

I am getting ClassCast Exception while i am clicking to button on the title bar.
My source code is as follows:

My activity code: 
  	
              public void onClick(View v) {

		if (v.getId() == R.id.about_us) {

			if (isInternetConnected()) {
				System.out.println("about us");
				startActivity(new Intent(GridDisplayActivity.this, AboutUsActivity.class));
			} else {
				setAlertBox("No Internet Connection");
			}
		}
		if (v.getId() == R.id.hard_copy) {

			if (isInternetConnected()) {
				System.out.println("hard copy");
				startActivity(new Intent(GridDisplayActivity.this,HardCopyActivity.class));
			} else {
				setAlertBox("No Internet Connection");
			}
		}

	}


Custom Application Code:
  

    public class CustomApplication extends Application {
   
    private Map<String, List<CustomAsyncTask<?,?,?>>> mActivityTaskMap;
 
    public CustomApplication() {
        mActivityTaskMap = new HashMap<String, List<CustomAsyncTask<?,?,?>>>();
    }
 
    public void removeTask(CustomAsyncTask<?,?,?> task) {
        for (Entry<String, List<CustomAsyncTask<?,?,?>>> entry : mActivityTaskMap.entrySet()) {
            List<CustomAsyncTask<?,?,?>> tasks = entry.getValue();
            for (int i = 0; i < tasks.size(); i++) {
                if (tasks.get(i) == task) {
                    tasks.remove(i);
                    break;
                }
            }
 
            if (tasks.size() == 0) {
                mActivityTaskMap.remove(entry.getKey());
                return;
            }
        }
    }
 
    public void addTask(Activity activity, CustomAsyncTask<?,?,?> task) {
        String key = activity.getClass().getCanonicalName();
        List<CustomAsyncTask<?,?,?>> tasks = mActivityTaskMap.get(key);
        if (tasks == null) {
            tasks = new ArrayList<CustomAsyncTask<?,?,?>>();
            mActivityTaskMap.put(key, tasks);
        }
 
        tasks.add(task);
    }
 
    public void detach(Activity activity) {
        List<CustomAsyncTask<?,?,?>> tasks = mActivityTaskMap.get(activity.getClass().getCanonicalName());
        if (tasks != null) {
            for (CustomAsyncTask<?,?,?> task : tasks) {
                task.setActivity(null);
            }
        }
    }
 
    public void attach(Activity activity) {
        List<CustomAsyncTask<?,?,?>> tasks = mActivityTaskMap.get(activity.getClass().getCanonicalName());
        if (tasks != null) {
            for (CustomAsyncTask<?,?,?> task : tasks) {
                task.setActivity(activity);
            }
        }
      }
   }

The logs that i am getting are:

    07-26 11:06:10.567: E/AndroidRuntime(381): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
    07-26 11:06:10.567: E/AndroidRuntime(381): 	at dalvik.system.NativeStart.main(Native Method)
    07-26 11:06:10.567: E/AndroidRuntime(381): Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.bespoken.android.provider.CustomApplication
    07-26 11:06:10.567: E/AndroidRuntime(381): 	at com.bespoken.android.GridDisplayActivity.onSaveInstanceState(GridDisplayActivity.java:567)
    07-26 11:06:10.567: E/AndroidRuntime(381): 	at android.app.Activity.performSaveInstanceState(Activity.java:1114)
    07-26 11:06:10.567: E/AndroidRuntime(381): 	at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1184)
     07-26 11:06:10.567: E/AndroidRuntime(381): 	at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2469)
     07-26 11:06:10.567: E/AndroidRuntime(381): 	... 12 more



Please guide me.
Thanks in advance.
