NullPointerException异常(@PhoneWindow:onKeyUpPanel:1002){}主力主力、异常、NullPointerException、PhoneWindow

2023-09-06 01:52:33 作者:Alexandr(嫁衣)

我在分析时得到奇怪的例外最近。

I get strange exceptions in my analytics lately.

java.lang.NullPointerException
at com.android.internal.policy.impl.PhoneWindow.onKeyUpPanel(PhoneWindow.java:1002)
at com.android.internal.policy.impl.PhoneWindow.onKeyUp(PhoneWindow.java:1703)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2114)
at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3626)
at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3596)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2839)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4904)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)

我缺少什么我可以做,以prevent这样的领先优势。

I am missing a lead on what I can do to prevent this.

推荐答案

LG之前修复这个问题(可能是几个月,视需要多长时间他们发布新固件),以下解决方法为我工作。只需添加以下code到你的活动类:

Until LG fixes this issue (which could be months, depending on how long it takes them to release new firmware), the following workaround worked for me. Just add the following code to your Activity class:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_MENU && "LGE".equalsIgnoreCase(Build.BRAND)) {
       return true;
   }
   return super.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_MENU && "LGE".equalsIgnoreCase(Build.BRAND)) {
       openOptionsMenu();
       return true;
   }
   return super.onKeyUp(keyCode, event);
}