Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pop up an Android dialog
    primarykey
    data
    text
    <p>I have the following code which doesn't work, what should I do to debug it?</p> <p>I created a new android 2.2 project, added a button and the button has:</p> <pre><code> android:onClick="Test" </code></pre> <p>the <code>Test()</code> function is here:</p> <pre><code>public void Test(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(this.getApplicationContext()); builder.setTitle("Title"); builder.setMessage("Message"); builder.setPositiveButton("ok", new OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub arg0.dismiss(); }}); builder.setCancelable(false); builder.create().show(); } </code></pre> <p>When it's triggered, the <code>show()</code> will cause this exception:</p> <pre><code>Thread [&lt;1&gt; main] (Suspended (exception WindowManager$BadTokenException)) &lt;VM does not provide monitor information&gt; AlertDialog(Dialog).show() line: 245 MainActivity.Test(View) line: 39 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 View$1.onClick(View) line: 2067 Button(View).performClick() line: 2408 View$PerformClick.run() line: 8817 ViewRoot(Handler).handleCallback(Message) line: 587 ViewRoot(Handler).dispatchMessage(Message) line: 92 Looper.loop() line: 143 ActivityThread.main(String[]) line: 4914 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 868 ZygoteInit.main(String[]) line: 626 NativeStart.main(String[]) line: not available [native method] </code></pre> <p>BTW There are some other things I tried: <a href="https://stackoverflow.com/questions/13331388/dialogfragment-doesnt-show-up/13332727#13332727">DialogFragment doesn&#39;t show up</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload