Get rid of all occurrences of getApplicationContext() from your code,
including the one shown in the snippet below. Use "this" instead
(minus the quotes), as that will be a perfectly valid Context, one
much better suited for your purposes.

On Tue, Jul 20, 2010 at 10:00 PM, Bret Foreman <bret.fore...@gmail.com> wrote:
> I'm getting an exception when I try to pop up an alert dialog from
> within the onOptionsItemSelected method of an Activity. The exception
> looks like this:
>
> W/WindowManager(   57): Attempted to add window with non-application
> token WindowToken{43c4d3b0 token=null}.  Aborting.
>
> I pasted the same code into a button's onClick method and it worked
> fine. Any ideas?
>
> Here's the code:
>
>                        AlertDialog alertDialog = new
> AlertDialog.Builder(getApplicationContext()).create();
>                        alertDialog.setTitle(R.string.confirmClear);
>                        alertDialog.setMessage(getString(R.string.areYouSure));
>                        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE,
> getString(R.string.yes), new DialogInterface.OnClickListener() {
>                          public void onClick(DialogInterface dialog, int 
> which) {
>                                /*
>                                * This is where we clear all the events from 
> the database.
>                                */
>                                // do something
>                        } });
>                        alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE,
> getString(R.string.no), new DialogInterface.OnClickListener() {
>                          public void onClick(DialogInterface dialog, int 
> which) {
>                               // don't do anything
>                            return;
>                        } });
>                        alertDialog.show();
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Beginners" group.
>
> NEW! Try asking and tagging your question on Stack Overflow at
> http://stackoverflow.com/questions/tagged/android
>
> To unsubscribe from this group, send email to
> android-beginners+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-beginners?hl=en
>



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.1 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to