在onFilterTouchEventForSecurity上获取NullPointerException

时间:2017-07-18 16:59:32

标签: java android nullpointerexception

我已经构建了应用程序,我集成了YouTube API,它运行正常,没有任何崩溃,但在Fabric上我检查了一些崩溃警告是ipf.onFilterTouchEventForSecurity。以下是崩溃的完整日志:

java.lang.NullPointerException: 
  at ipf.onFilterTouchEventForSecurity(ipf.java:115)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2351)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2844)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2461)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2844)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2461)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2844)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2461)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2876)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2461)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2844)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2519)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2844)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2519)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2844)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2519)
  at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2840)
  at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1853)
  at android.app.Activity.dispatchTouchEvent(Activity.java:3061)
  at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2801)
  at android.view.View.dispatchPointerEvent(View.java:10246)
  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5447)
  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5283)
  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4721)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4774)
  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4740)
  at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4882)
  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4748)
  at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4939)
  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4721)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4774)
  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4740)
  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4748)
  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4721)
  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7429)
  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7298)
  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7259)
  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7539)
  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
  at android.os.MessageQueue.nativePollOnce(MessageQueue.java:0)
  at android.os.MessageQueue.next(MessageQueue.java:323)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:7325)
  at java.lang.reflect.Method.invoke(Method.java:0)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

我知道这个问题不是因为代码,而是我需要防止崩溃。

以下是我面临问题的设备列表:

  1. 三星Galaxy J7(j7elte),1536MB RAM,Android 6.0
  2. 小米Redmi Note 3(kenzo),2048MB RAM,Android 6.0
  3. 联想TB3-710F(TB3-710F),1024MB RAM,Android 5.0
  4. 小米Redmi 3S(陆地),2048MB RAM,Android 6.0
  5. LeTV Le 2(le_s2_ww),3072MB RAM,Android 6.0
  6. LGE LG Stylus2 4G(ph2),2048MB RAM,Android 6.0
  7. Infocus M2_3G(G10),10124MB RAM,Android 4.4

2 个答案:

答案 0 :(得分:0)

我无法复制它,但是您可以尝试以下几种操作:

如果可能的话,请尝试从suggested中添加android:filterTouchesWhenObscured=false作为透明的docs

  

指定当视图的窗口模糊时是否过滤触摸   在另一个可见的窗口旁边。设置为true时,视图将不接收   每当烤面包,对话框或其他窗口出现在菜单上方时,   视图的窗口。有关更多信息,请参阅View安全性文档。   详细信息。

     

可能是布尔值,例如“ true”或“ false”。

否则,您可以尝试覆盖根视图的分发方法 并在其中放置try catch,可以根据需要将其用作custom Component

@Override
void dispatchTouchEvent(MotionEvent event){
    try{
        super.dispatchTouchEvent(event);
    }
    catch (Exception e){
        e.printStackTrace();
    }
}

答案 1 :(得分:-1)

检查您是否必须对空值进行操作。这将始终生成 NPE。 例如a-null-expression.anyMethodCall();

在调用 anyMethodCall() 时验证点之前的任何表达式都不能为空。