Reputation: 157
I'm trying to display an AlertDialog
but I get an error when I call the show
function. I use the following code, copied from the Hello Mapview
code sample :
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(article.getTitle());
dialog.setMessage(article.getSnippet());
dialog.show();
The application crashes when the last line is being executed. I have suspected the context
variable but it is not guilty because, with it, I can display a Toast
.
Thanks in advance for the time you will spend trying to help me.
Upvotes: 0
Views: 212
Reputation: 2584
Second @Brigham. Make sure the context you pass to your ItemizedOverylay is the activity which displays the MapView. In other words, use something like the following,
itemizedOverlay = new HelloItemizedOverlay(drawable, this);
Instead of
itemizedOverlay = new HelloItemizedOverlay(drawable, getApplicationContext());
Application context can't be used for AlertDialog, and will result in the following error,
ERROR/AndroidRuntime(8679): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
Upvotes: 1
Reputation: 3658
I guess everything will work.. In the below code snippet
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(article.getTitle());
dialog.setMessage(article.getSnippet());
dialog.show();
make this change
AlertDialog dialog = new AlertDialog.Builder(context);
dialog.setTitle(article.getTitle());
dialog.setMessage(article.getSnippet());
dialog.show();
Upvotes: 0
Reputation: 2661
You need to call .create() after you create the new AlertDialog.Builder object.
Upvotes: 0