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. Google Maps Installation error

I have an "Android Dev Phone 1" Firmware version 1.6 and for the last month or 
so it has been trying to update Google Maps but it keeps getting "Installation 
error Package file was not signed correctly".

I have done a search on the Internet and a number of people have successfully 
completed this update and a number of others have received this same error 
message.  But I have not been able to find a solution to the "not signed 
correctly" problem.

Does anyone here know how to get Google Maps to update correctly?


2. Program unique identifier

Hi All,
    As known, we can get devcie  unique ID using
TelephonyManager#getDeviceId() . So, does a program have an unique
identifier? How can I get it?  I googled it but got nothing.



3. How to play sdp in MediaPlayer

4. Android Map API Key

5. Does ANYONE HAVE ANY IDEA WHY THIS CODE WILL NOT PLLAY VIDEO..Video From Youtube in Emulator Android 2.1 Eclipse Gallileo/ Unable to play video

6. start another activity through onclick event

7. Circular (closed) ListView