0

when i am browsing in my app i get sometimes this error. I am not sure this error comes randomly and i can't find out why. The Log doesn't show anything specific to my application?

I hope someone could give me a tip or a hint why this error occoures. (The last time it came when i tried to open a popup, a Quickaction Dialog, after occouring a second time with the same Quickaction Dialog it worked again after i tried it a 3rd time. And now it works all the time, again?)

08-01 11:09:15.980: ERROR/AndroidRuntime(9579): FATAL EXCEPTION: main
08-01 11:09:15.980: ERROR/AndroidRuntime(9579): java.lang.NullPointerException
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at android.widget.PopupWindow$PopupViewContainer.dispatchKeyEvent(PopupWindow.java:1445)
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2664)
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at android.view.ViewRoot.deliverKeyEvent(ViewRoot.java:2629)
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1935)
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at android.os.Looper.loop(Looper.java:143)
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at android.app.ActivityThread.main(ActivityThread.java:4196)
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at java.lang.reflect.Method.invokeNative(Native Method)
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at java.lang.reflect.Method.invoke(Method.java:507)
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 11:09:15.980: ERROR/AndroidRuntime(9579):     at dalvik.system.NativeStart.main(Native Method)

Here some more details:

QuickAction qa = QuickactionBuilder.showSaveForgetQuickaction();

                qa.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
                    @Override
                    public void onItemClick(int pos) {
                        if (pos == 0) { // SAVE
                            Toast.makeText(ctxHolder.getCtx(), "TODO SAVE", Toast.LENGTH_SHORT).show();
                        } else if (pos == 1) { // REJECT
                            Toast.makeText(ctxHolder.getCtx(), "REJECTED", Toast.LENGTH_SHORT).show();
                        } else { // CANCEL
                            Toast.makeText(ctxHolder.getCtx(), "CANCEL", Toast.LENGTH_SHORT).show();
                        }
                    }
                });

                qa.show(v);

THe QuickactionBuilder only creates the QuickAction Dialog for me. That's as simple as: (Only to show the basics of that method)

QuickAction qa = new QuickAction
ActionItem ai = new ActionItem() 
// some setters ...

qa.add(ai)

return qa;
2
  • can u display your used code here Commented Aug 1, 2011 at 9:19
  • The problem is the error message doesn't say anything about my code it's only this piece of information. The error occoures randomly. So no idea. But i will add the piece of code where it appeared the last time. Commented Aug 1, 2011 at 9:24

3 Answers 3

1

I had the same problem with QuickAction i received crashes from users although i couldn't reproduce them on my devices so if anyone still needs the solution i'd be glad to share it

the idea is to avoid of using PopupViewContainer in PopupWindow because the crash bug is in its dispatchKeyEvent(KeyEvent event) method. The only way i could do that is to keep backgroundDrawable == null. Then you have to handle outside touches and Back button yourself.

PopupWindows Class:

public PopupWindows(Context context) {
    mContext    = context;

    mWindow     = new PopupWindow(context);
    mWindow.setBackgroundDrawable(null);
    ......
}

protected void onShow() {   

    if (mRootView == null) {
        return;
    }

    if (mRootView instanceof CustomRelativeLayout) {
        ((CustomRelativeLayout)mRootView).setDispatchKeyEventListener(new CustomRelativeLayout.OnDispatchKeyEventListener() {

            @Override
            public void onDispatchKeyEvent(KeyEvent event) {
                if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && mWindow.isShowing()) {
                    dismiss();
                }
            }
        });
    }       

    mRootView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN && mWindow.isShowing()) {
                dismiss();
                return true;
            }
            return false;
        }
    });

}

Do not set any drawable here:

protected void preShow() {
    if (mRootView == null) 
        throw new IllegalStateException("setContentView was not called with a view to display.");

    onShow();

    mWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
    mWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    mWindow.setTouchable(true);
    mWindow.setFocusable(true);
    mWindow.setOutsideTouchable(true);

    mWindow.setContentView(mRootView);
}

And everything next is classic

CustomRelativeLayout:

public class CustomRelativeLayout extends RelativeLayout {

public CustomRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public CustomRelativeLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomRelativeLayout(Context context) {
    super(context);
}

private OnDispatchKeyEventListener mOnDispatchKeyEventListener;



public void setDispatchKeyEventListener(OnDispatchKeyEventListener listener) {
    mOnDispatchKeyEventListener = listener;
}

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (mOnDispatchKeyEventListener != null) {
        mOnDispatchKeyEventListener.onDispatchKeyEvent(event);
    }
    return super.dispatchKeyEvent(event);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    return super.onTouchEvent(event);
}   

public static interface OnDispatchKeyEventListener {
    public void onDispatchKeyEvent(KeyEvent event);
}
}

popup_vertical.xml and popup_horizontal.xml:

just use com.your.package.CustomRelativeLayout instead of top level RelativeLayout

Hope this will help

Sign up to request clarification or add additional context in comments.

Comments

0

You must be doing some expensive operation on the UI thread. I would suggest you to move those operations to a separate non-UI thread. Post more code to identify the pain area though.

Comments

0

This answer is very old now. I came to the solution that this problem is caused by the Quickaction Library istelf. My solution was to use a different Library.

It's different but it works great too. This library comes also with a few more features.

Check it out: http://greendroid.cyrilmottier.com/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.