I'm having an issue with the onCreateContextMenu throwing a error only on API 15 & 16. It works perfectly fine on every other API from API 8 to API 17 (my min and max targets).

I did my best to try and solve this issue on my own by searching through Google, but after about a week I've became desperate enough to plead for help from the wonderful stack overflow community.

**The onCreateContextMenu method**

```
@Override
public void onCreateContextMenu(android.view.ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    Log.i(TAG, "Create context menu");

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.context_menu_my_time_zone, menu);

    Log.i(TAG, "Context menu created.");
}

```

**The Containing Class**

```
public class MyTimeZoneTActivity extends ListActivity {
    // I can post the code for the Class if required.
}

```

**The Exception**

```
02-14 09:38:20.828: E/AndroidRuntime(10912): FATAL EXCEPTION: main
02-14 09:38:20.828: E/AndroidRuntime(10912): java.lang.ClassCastException: com.creativitality.labs.timezoneswidget.MyTimeZonesActivity cannot be cast to android.app.Application
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.view.Window.getCompatInfo(Window.java:481)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.view.Window$LocalWindowManager.<init>(Window.java:491)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.view.Window.setWindowManager(Window.java:477)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.view.Window.setWindowManager(Window.java:460)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.app.Dialog.<init>(Dialog.java:163)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.app.AlertDialog.<init>(AlertDialog.java:114)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.app.AlertDialog$Builder.create(AlertDialog.java:913)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at com.android.internal.view.menu.MenuDialogHelper.show(MenuDialogHelper.java:79)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at com.android.internal.view.menu.ContextMenuBuilder.show(ContextMenuBuilder.java:88)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at com.android.internal.policy.impl.PhoneWindow$DecorView.showContextMenuForChild(PhoneWindow.java:2201)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:612)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:612)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:612)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:612)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.widget.AbsListView.performLongPress(AbsListView.java:2926)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:2871)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.os.Handler.handleCallback(Handler.java:615)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.os.Looper.loop(Looper.java:137)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at android.app.ActivityThread.main(ActivityThread.java:4745)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at java.lang.reflect.Method.invokeNative(Native Method)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at java.lang.reflect.Method.invoke(Method.java:511)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-14 09:38:20.828: E/AndroidRuntime(10912):    at dalvik.system.NativeStart.main(Native Method)

```

---

**Anything else I can provide?**

Let me know if there is any other information I can provide to help solve this issue.

Thank you all in advance!

---

Additional Code (as requested)
------------------------------

**ListActivity**

```
public class MyTimeZonesActivity extends ListActivity {

    // Define application context
    private Context applicationContext;

    //LIST OF ARRAY STRINGS WHICH WILL SERVE AS LIST ITEMS
    List<TimeZoneData> timeZoneData = null;

    //DEFINING STRING ADAPTER WHICH WILL HANDLE DATA OF LISTVIEW
    ArrayAdapter<String> adapter;
    TimeZoneAdaptor timezoneAdaptor = null;

    public static final int INSTRUCTIONS_CODE = 0;
    private static final String TAG = "MyTimeZonesActivity";

    SharedPreferences sharedPref;
    SharedPreferencesHelper sharedPreferencesHelper;

    TimeZonesApplication timeZonesApplication;

    public Context getApplicationContext(){
        return applicationContext;
    }

    @Override
    public void onCreate(Bundle savedInstanceState){
        Log.i(TAG, "My Time Zone Activity - onCreate called.");
        super.onCreate(savedInstanceState); 

        // Get Application Globals
        timeZonesApplication = (TimeZonesApplication)getApplicationContext();

        // Set application context
        applicationContext = this;

        // Populate time zone data
        timeZoneData = new ArrayList<TimeZoneData>();
        getStoredTimeZonesData(); // Populates timeZoneData object with stored time zone data

        setContentView(R.layout.activity_my_time_zones);
        timezoneAdaptor = new TimeZoneAdaptor(this, R.layout.timezone_view_mine, timeZoneData);
        setListAdapter(timezoneAdaptor);

        registerForContextMenu(getListView());

    }

```

**ArrayAdapter**

```
public class TimeZoneAdaptor extends ArrayAdapter<TimeZoneData> {
    private String TAG = "TimeZoneAdaptor";
    //private ArrayList<TimeZoneData> mOrigionalValues;
    private List<TimeZoneData> mObjects;

    public TimeZoneAdaptor(Context context, int textViewResourceId, List<TimeZoneData> objects) {
        super(context, textViewResourceId, objects);
        this.mObjects = objects;
        //this.mOrigionalValues = new ArrayList<TimeZoneData>(objects);
    }

    @Override
    public int getCount() {
        return ((null != mObjects) ? mObjects.size() : 0);
    }

    @Override
    public TimeZoneData getItem(int position) {
        return ((null != mObjects) ? mObjects.get(position) : null);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
    }

    public void add(TimeZoneData timeZone)
    {
        Log.w(TAG, "Add time zone: " + timeZone.id);
        mObjects.add(timeZone);
        notifyDataSetChanged();
    }

    public void remove(int position){
        Log.i(TAG, "Remove object from adapter at position: " + position);
        mObjects.remove(position);
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;

        if (null == view) {
            LayoutInflater vi = (LayoutInflater) MyTimeZonesActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = vi.inflate(R.layout.timezone_view_mine, null);
        }

        TimeZoneData data = mObjects.get(position);

        if (null != data) {
            TextView textCountry = (TextView) view.findViewById(R.id.timezone_country);
            TextView textName = (TextView) view.findViewById(R.id.timezone_name);
            TextView textTime = (TextView) view.findViewById(R.id.timezone_time);

            textCountry.setText(data.country.toUpperCase(Locale.getDefault()));
            textName.setText(data.city);
            textTime.setText(data.time);

            //view.setOnClickListener(new OnItemClickListener(position)); // NOT REQUIRED as we are setting in on activity level
        }

        return view;
    }
    }

```