Log in or register to post comments

Dialog

June 20, 2011 - 10:12am #1

I edit the dominoes app..so when i click the delete button, it will show dialog, i made a code like this on GUImanager.java, initbutton method :

deleteButton = (Button) overlayView.findViewById(R.id.delete_button);
        deleteButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

               AlertDialog.Builder aboutDialog = new AlertDialog.Builder(applicationContext);
            			aboutDialog.setMessage("test");	
            			/*Retry*/
            			aboutDialog.setNegativeButton("test", new DialogInterface.OnClickListener() {
            				public void onClick(DialogInterface dialog, int id) {
            					dialog.dismiss();
            				}
            			});
            			AlertDialog aboutAlert = aboutDialog.create();
            			aboutAlert.setTitle("test");
            			aboutAlert.show();

            }
        });

but when i click on the deletebutton, the dominoes app force close..anyone know why that happen??did i make a mistake??

Re: Dialog

June 25, 2011 - 8:05am #6

You might try moving this code into the main activity... It looks like Android AlertDialogs are quite picky about where they are created/shown from. There are lots of posts online with people having similar issues, e.g. http://stackoverflow.com/questions/1561803/android-progressdialog-show-crashes-with-getapplicationcontext

- Kim

Re: Dialog

June 24, 2011 - 12:42am #5

yeah, i modified my code just like dominoes app..so the applicationContext is result of method getApplicationContext() from imagetargets.java..i have a problems in line "aboutalert.show"..i cannot send my dialog to the activity..

Re: Dialog

June 22, 2011 - 2:58pm #4

If I had to guess I'd say your applicationContext is null. Are you setting this?

- Kim

Re: Dialog

June 22, 2011 - 8:02am #3

this is my logcat display when my app force close :

06-22 22:00:32.075: ERROR/AndroidRuntime(14337): FATAL EXCEPTION: main
06-22 22:00:32.075: ERROR/AndroidRuntime(14337): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at android.view.ViewRoot.setView(ViewRoot.java:509)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at android.app.Dialog.show(Dialog.java:241)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at org.ARmap.GUIManager$2.onClick(GUIManager.java:136)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at android.view.View.performClick(View.java:2408)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at android.view.View$PerformClick.run(View.java:8816)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at android.os.Handler.handleCallback(Handler.java:587)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at android.os.Looper.loop(Looper.java:123)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at android.app.ActivityThread.main(ActivityThread.java:4633)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at java.lang.reflect.Method.invokeNative(Native Method)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at java.lang.reflect.Method.invoke(Method.java:521)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-22 22:00:32.075: ERROR/AndroidRuntime(14337):     at dalvik.system.NativeStart.main(Native Method)
06-22 22:00:32.075: WARN/ActivityManager(173):   Force finishing activity org.ARmap/.ImageTargets

Re: Dialog

June 22, 2011 - 2:40am #2

Could you post a logcat of the force close?

Log in or register to post comments