2011-07-14 7 views
0

AlertDialogを表示しようとしていますが、show関数を呼び出すとエラーが発生します。最後の行が実行されているとき「AlertDialog」の問題

AlertDialog.Builder dialog = new AlertDialog.Builder(context); 
    dialog.setTitle(article.getTitle()); 
    dialog.setMessage(article.getSnippet()); 
    dialog.show(); 

アプリケーションがクラッシュ:私は、Hello Mapviewコードサンプルからコピーし、次のコードを、使用します。私はcontext変数を疑っていますが、それと無関係なので、Toastを表示できます。

あなたが私を助けるために過ごす時間を事前に感謝します。

+0

可能であれば、ここにエラーログを投稿してください。 – Chandan

答えて

1

セカンド@Brighamを作ります。 ItemizedOverylayに渡すコンテキストがMapViewを表示するアクティビティであることを確認してください。言い換えれば、以下、

itemizedOverlay = new HelloItemizedOverlay(drawable, this); 

代わりの

itemizedOverlay = new HelloItemizedOverlay(drawable, getApplicationContext()); 
アプリケーションコンテキストはAlertDialogのために使用することができず、次のエラーになります

ERROR /のようなものを使用AndroidRuntime(8679):android.view.WindowManager $ BadTokenException:ウィンドウを追加できません - アプリケーションのトークンnullはありません

0

新しいAlertDialog.Builderオブジェクトを作成した後で.create()を呼び出す必要があります。以下のコードスニペットで

0

私はすべてがうまくいくと思います。..

AlertDialog.Builder dialog = new AlertDialog.Builder(context); 
    dialog.setTitle(article.getTitle()); 
    dialog.setMessage(article.getSnippet()); 
    dialog.show(); 

この変更

AlertDialog dialog = new AlertDialog.Builder(context); 
    dialog.setTitle(article.getTitle()); 
    dialog.setMessage(article.getSnippet()); 
    dialog.show();