I'm trying to create a PopupWindow inside of TextView.java, which
works fine when in Portrait/non-fullscreen mode, but when I go into
Landscape/ExtractEditText, then I get an exception about my activity
being null.

In TextView.java, I have:
...
    private PopupWindow mCursorPopup;
...
on touch:
        if (null == mCursorPopup) {
            final CursorPopupView popupView = new CursorPopupView
(mContext);
            mCursorPopup = new PopupWindow(this);
            popupView.initialize(mCursorPopup, this);
        }
...

Then I'm trying to show the PopupWindow in CursorPopupView with:
mWindow.showAtLocation(this, Gravity.NO_GRAVITY, x, y);

This causes the following exception:
08-13 18:09:13.185: ERROR/AndroidRuntime(1754): Uncaught handler:
thread main exiting due to uncaught exception
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):
android.view.WindowManager$BadTokenException: Unable to add window --
token null is not valid; is your activity running?
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.view.ViewRoot.setView(ViewRoot.java:430)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:178)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.widget.PopupWindow.invokePopup(PopupWindow.java:797)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.widget.PopupWindow.showAtLocation(PopupWindow.java:665)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.text.method.CursorPopupView.showAtCurrentCursorPosition
(CursorPopupView.java:222)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.widget.TextView.enterCursorPlacementMode(TextView.java:3268)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.text.method.ArrowKeyMovementMethod.onTouchEvent
(ArrowKeyMovementMethod.java:227)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.widget.TextView.onTouchEvent(TextView.java:6442)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.view.View.dispatchTouchEvent(View.java:3483)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:802)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:802)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:802)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:802)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:802)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:802)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
com.android.internal.policy.impl.PhoneWindow
$DecorView.superDispatchTouchEvent(PhoneWindow.java:1709)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent
(PhoneWindow.java:1199)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.app.Dialog.dispatchTouchEvent(Dialog.java:588)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
com.android.internal.policy.impl.PhoneWindow
$DecorView.dispatchTouchEvent(PhoneWindow.java:1693)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.view.ViewRoot.handleMessage(ViewRoot.java:1588)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.os.Handler.dispatchMessage(Handler.java:99)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.os.Looper.loop(Looper.java:123)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
android.app.ActivityThread.main(ActivityThread.java:4020)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
java.lang.reflect.Method.invokeNative(Native Method)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
java.lang.reflect.Method.invoke(Method.java:521)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-13 18:09:13.195: ERROR/AndroidRuntime(1754):     at
dalvik.system.NativeStart.main(Native Method)

I think I may misunderstand some relationship between Contexts,
Activities, and InputServiceManager. The exception seems to indicate
an Activity is required, but PopupWindow only requires a Context,
which doesn't have to be an Activity.

As Romain mentioned other posts, this exception normally means that
you're creating your View too early or too late, but I don't think
that's the case in what I'm trying to do.

Any suggestions / explanation?

Thanks
--~--~---------~--~----~------------~-------~--~----~
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