Dialog problem

by Andr茅 » Wed, 10 Feb 2010 05:24:51 GMT

Sponsored Links

I'm trying to make a dialog box to open when I start a program.
Eclipse likes my code, I like my code =), but the emulator does not
like my code. It says that something went totally worong and the
application has to shut  down. Bellow you can see my code. When I run
it in debug mode everything seems to go as it should but when it gets
to "return dialog; " eclipse debug windows says source not found.
Anyone have any suggestions?


package com.test.popup;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

public class popup extends Activity {
        static final int DIALOG_NEW = 0;
        static final int DIALOG_NEW2 = 1;

    public void onCreate(Bundle savedInstanceState) {
    protected Dialog onCreateDialog(int id) {
        Context mContext = getApplicationContext();
        Dialog dialog = new Dialog(mContext);
        switch(id) {
        case DIALOG_NEW:
                dialog.setTitle("Custom Dialog");

                TextView text = (TextView) dialog.findViewById(R.id.text);
                text.setText("Hello, this is a custom dialog!");
        case DIALOG_NEW2:
                dialog.setTitle("Custom Dialog");

                TextView text2 = (TextView) dialog.findViewById(R.id.text);
                text2.setText("Hello, this is a custom dialog!2");
            dialog = null;
        return dialog;


Dialog problem

by Andr茅 » Wed, 10 Feb 2010 05:33:18 GMT

 Oooh, I tried to follow this explanation:

 http://developer.android.com/intl/de/guide/topics/ui/dialogs.html #CustomDialog

if anyone wants to have a look at it!


Sponsored Links

Dialog problem

by TreKing » Wed, 10 Feb 2010 05:33:25 GMT


You're probably seeing something about a BadToken in the debug log, yes?
DO NOT use getApplicationContext(). Use your current activity or the context
from one of your views.

I swear someone runs into this every single day ...

TreKing - Chicago transit tracking app for Android-powered devices


Dialog problem

by Andr茅 » Wed, 10 Feb 2010 05:39:37 GMT


Yeah, now I saw your other replies. You are the man! Thanks!


Dialog problem

by Bob Kerns » Wed, 10 Feb 2010 07:05:19 GMT

 The four stages of Android UI Enlightenment:

0) You dutifully use getApplicationContext() his Activity to pass
along to the SDK.
1) You realize you don't NEED to call getApplicationContext() from
your Activity to pass along, 'this' should work.
2) You realize it is WRONG to call getApplicationContext() from your
Activity to pass along, because that's not the right context to pass
along -- your Activity is.
3) You wonder why the documentation and various failing examples keep
saying to use getApplicationContext()?
4) I am still stuck at stage 3. Can you enlighten me?

Really, can't someone take a half-hour and go through all the
occurrences of getApplicationContext() in documentation, Javadoc, and
examples, and fix them? Except for the Javadoc for
getApplicationContext(), nearly all occurrences should probably be


Dialog problem

by Lance Nanek » Wed, 10 Feb 2010 09:58:04 GMT

 More stars/occurrences on the bug report welcome:


Other Threads

1. How to do locale setting?

Hellow developers,

I wanna add or remove locale items which are in Settings->Locale &
Text->Select locale, I don't know how to do it. Would you like to give
me some information about it?



2. shoutcast aac/aacp player available at market com.leadapps.android.radio

shoutcast aac/aacp player available at market


3. first time android usage

4. ExpandableListView not expanding/collapsing when using a group View with a checkbox

5. Ability to quit an app after trial period?

6. TabHost and MapView

7. can not resume from suspend [was Cursor.patch fails]