Try getBaseContext();

Thanks and Regards,
Kumar Bibek

On Mar 16, 1:50 am, Dirk Vranckaert <[email protected]> wrote:
> I'm trying to create a custom dialog in my application to show an
> about window but it ain't working. Maybe one of you knows a solution?
>
> So I have an activity with the onCreateDialog(int id) overriden in it:
>
>         @Override
>         protected Dialog onCreateDialog(int id) {
>                 Dialog dialog = null;
>                 switch (id) {
>                         case EPISODE_LOADING_DIALOG:
>                                 ...
>                         case EXCEPTION_DIALOG:
>                                 ...
>                         case ABOUT_DIALOG:
>                                 dialog = new Dialog(getApplicationContext());
>                                 dialog.setContentView(R.layout.aboutdialog);
>                                 dialog.setTitle("MyTitle");
>                                 break;
>                         default:
>                                 ...
>                 }
>                 return dialog;
>         }
>
> My aboutdialog layout files looks like this:
>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
>               android:orientation="vertical"
>               android:layout_width="fill_parent"
>               android:layout_height="fill_parent"
>               android:padding="10dp"
>               >
>     <TextView android:id="@+id/aboutText"
>               android:layout_width="wrap_content"
>               android:layout_height="fill_parent"
>               android:textColor="#FFF"
>               android:text="@string/aboutText"
>               />
> </LinearLayout>
>
> This is exactly as described 
> here:http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
> However this my exception thrown:
>
> 03-15 21:48:32.055: ERROR/AndroidRuntime(2004): Uncaught handler:
> thread main exiting due to uncaught exception
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):
> android.view.WindowManager$BadTokenException: Unable to add window --
> token null is not for an application
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.view.ViewRoot.setView(ViewRoot.java:429)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.view.WindowManagerImpl.addView(WindowManagerImpl.java:178)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.app.Dialog.show(Dialog.java:231)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.app.Activity.showDialog(Activity.java:2407)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> eu.vranckaert.episodeWatcher.EpisodesWatchListActivity.onOptionsItemSelected(EpisodesWatchListActivity.java:
> 130)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.app.Activity.onMenuItemSelected(Activity.java:2085)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:
> 820)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:
> 139)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:
> 813)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:
> 519)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:
> 122)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.view.View.onTouchEvent(View.java:3828)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.widget.TextView.onTouchEvent(TextView.java:6291)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.view.View.dispatchTouchEvent(View.java:3368)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> com.android.internal.policy.impl.PhoneWindow
> $DecorView.dispatchTouchEvent(PhoneWindow.java:1691)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.view.ViewRoot.handleMessage(ViewRoot.java:1525)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.os.Handler.dispatchMessage(Handler.java:99)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.os.Looper.loop(Looper.java:123)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> android.app.ActivityThread.main(ActivityThread.java:3948)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> java.lang.reflect.Method.invokeNative(Native Method)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> java.lang.reflect.Method.invoke(Method.java:521)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> com.android.internal.os.ZygoteInit
> $MethodAndArgsCaller.run(ZygoteInit.java:782)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
> 03-15 21:48:32.130: ERROR/AndroidRuntime(2004):     at
> dalvik.system.NativeStart.main(Native Method)

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to