Problem with AlertDialog.Builder

by Ivan Longin » Tue, 23 Feb 2010 12:14:09 GMT


Sponsored Links
 Hi everyone.
I'm having problem with creating AlertDialog. I would like that
AlertDialog appears when i click on one button, so i put all code for
creating dialog in that button listener...the same code works outside
that listener but inside listener doesn't work...it doesn't call any
errors but when i start emulator written is something about this:
Aplication has terminater unexpected"....

This is my code for that:

btsenddata.setOnClickListener(new Button.OnClickListener() {


                public void onClick (View v){

                                AlertDialog.Builder alt_bld = new
AlertDialog.Builder(getApplicationContext() );
                                alt_bld.setMessage("Do you want to close this 
window ?")
                                .setCancelable(false)
                                .setPositiveButton("Yes", new
DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int 
id) {
                                // Action for 'Yes' Button
                                }
                                })
                                .setNegativeButton("No", new 
DialogInterface.OnClickListener()
{
                                public void onClick(DialogInterface dialog, int 
id) {
                                //  Action for 'NO' Button
                                dialog.cancel();
                                }
                                });
                                AlertDialog alert = alt_bld.create();
                                // Title for AlertDialog
                                alert.setTitle("Title");
                                // Icon for AlertDialog
                                alert.setIcon(R.drawable.icon);
                                alert.show();
                }});


.... i've heard that method getApplicationContext() is creating some
problems but i've tried replace it with activity.this and it doesn't
work anyway...

--



Problem with AlertDialog.Builder

by TreKing » Tue, 23 Feb 2010 23:37:41 GMT


 



What do you mean it doesn't work anyway? What happens when you use the
activity (what you should be doing)?

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--


Sponsored Links


Other Threads

1. Export sms Hero to csv

Dear All,

Apakah memungkinkan untuk export sms dari Hero menjadi file? Ext csv misalnya.
Jika tidak, apakah ada cara lain untuk memindahkan sms dari Hero tsb
ke Milestone?

Terima kasih banyak sebelumnya.

Anton

-- 
Sent from my mobile device

-- 
=========================
Google Groups "Indonesian Android Community [id-android]" group.

To post to this group, send email to id-android@googlegroups.com

To request to subscribe to this group:

Click  

2. MediaPlayer cannot play music file in res/raw folder

Hello,

I am trying to make an app that simply plays an mp3 file when you
click on a button.  I've based my code off the API Demos from the
android website, and I've been scouring various Android developer
boards but all the solutions are still resulting in the same problem.

When you click on the button this code should be executed:

    private void playAudio(Integer media){
        MediaPlayer m = MediaPlayer.create(this, R.raw.b);
        m.start();
    }

When the program gets executed and I click on the button the program
crashes.  All I've been able to determine from the stack trace is
that:
1 - The resource file cannot be found
or
2 - I am not able to open the file descriptor for some reason (it's
compressed?)

Here is the stack trace I am getting from logcat:
E/AndroidRuntime( 1425): Uncaught handler: thread main exiting due to
uncaught
exception
E/AndroidRuntime( 1425): java.lang.RuntimeException: Unable to start
activity ComponentInfo{org.me.demogo/org.me.demogo.DemoGoPlayer}:
android.content.res.Resources$NotFoundException: File res/raw/a.mp3
from drawable resource ID
#0x7f040000
E/AndroidRuntime( 1425):        at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2268)
E/AndroidRuntime( 1425):        at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
E/AndroidRuntime( 1425):        at android.app.ActivityThread.access
$1800(ActivityThread.java:
112)
E/AndroidRuntime( 1425):        at android.app.ActivityThread
$H.handleMessage(ActivityThread.java:
1692)
E/AndroidRuntime( 1425):        at android.os.Handler.dispatchMessage
(Handler.java:
99)
E/AndroidRuntime( 1425):        at android.os.Looper.loop(Looper.java:
123)
E/AndroidRuntime( 1425):        at android.app.ActivityThread.main
(ActivityThread.java:
3948)
E/AndroidRuntime( 1425):        at
java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 1425):        at java.lang.reflect.Method.invoke
(Method.java:
521)
E/AndroidRuntime( 1425):        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:
782)
E/AndroidRuntime( 1425):        at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
540)
E/AndroidRuntime( 1425):        at dalvik.system.NativeStart.main
(Native
Method)
E/AndroidRuntime( 1425): Caused by: android.content.res.Resources
$NotFoundException: File res/raw/a.mp3 from drawable resource ID
#0x7f040000
E/AndroidRuntime( 1425):        at
android.content.res.Resources.openRawResourceFd(Resources.java:
814)
E/AndroidRuntime( 1425):        at android.media.MediaPlayer.create
(MediaPlayer.java:
550)
E/AndroidRuntime( 1425):        at org.me.demogo.DemoGoPlayer.playAudio
(DemoGoPlayer.java:
29)
E/AndroidRuntime( 1425):        at org.me.demogo.DemoGoPlayer.onCreate
(DemoGoPlayer.java:
25)
E/AndroidRuntime( 1425):        at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
E/AndroidRuntime( 1425):        at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2231)
E/AndroidRuntime( 1425):        ... 11
more
E/AndroidRuntime( 1425): Caused by: java.io.FileNotFoundException:
This file can not be opened as a file descriptor; it is probably
compressed
E/AndroidRuntime( 1425):        at
android.content.res.AssetManager.openNonAssetFdNative(Native
Method)
E/AndroidRuntime( 1425):        at
android.content.res.AssetManager.openNonAssetFd(AssetManager.java:
412)
E/AndroidRuntime( 1425):        at
android.content.res.Resources.openRawResourceFd(Resources.java:
811)
E/AndroidRuntime( 1425):        ... 16 more

Thank you,
CS

--

3. Eclipse error when trying to install the ADT Plugin

4. Google Map is not displaying in emulator

5. Specify URL for Uri.parse() in resource file?

6. can't write to sdcard anymore

7. Selection