0

We have an enterprise application being developed, and since the project inception, we're facing a constant crash only in OnePlus Nord devices.

We tried to reproduce in our devices, and it's not getting reproduced, but Firebase Crashlytics always reports it in live application. Description as:

cpe.java line 11

com.oneplus.theme.cpe.onViewAttachedToWindow

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.removeOnAttachStateChangeListener(android.view.View$OnAttachStateChangeListener)' on a null object reference
       at com.oneplus.theme.cpe.onViewAttachedToWindow(cpe.java:11)
       at android.view.View.dispatchAttachedToWindow(View.java:20272)
       at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3455)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2273)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1960)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8228)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
       at android.view.Choreographer.doCallbacks(Choreographer.java:1041)
       at android.view.Choreographer.doFrame(Choreographer.java:953)
       at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:1163)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7711)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

At this stage, as it is working fine on all other devices, we couldn't pinpoint any code which could be causing this issue.

Being reported with many OnePlus Nord users, this issue brings our crash free % down significantly! How to fix this?

Dhanesh Katre
  • 99
  • 2
  • 7
  • 1
    It doesn't look like a OnePlus specific bug. Post your code? – OhhhThatVarun Jul 12 '21 at 05:57
  • @OhhhThatVarun it's actually difficult to pinpoint the code.. We have a parent HomeActivity (with 3 nav tabs), from which users can navigate to multiple places.. The last activity Crashlytics mentions is on the HomeActivity itself.. that's pretty much vague! And we couldn't even reproduce this one! Crashlytics reports all crashes for OnePlus Nord devices only, so we eliminated possibility on other devices.. – Dhanesh Katre Jul 12 '21 at 07:58
  • You are expecting me to help you investigate without looking at your code? – OhhhThatVarun Jul 12 '21 at 08:07

1 Answers1

0

It's some view related problem I think. It's saying that you're using listener on null view object. So check if you are getting the view first & then applying listener. You can use GlobalLayoutListener to check if the view has finished Drawing.

yourView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

@Override
public void onGlobalLayout() {
  yourView.getViewTreeObserver()
                    .removeOnGlobalLayoutListener(this);
    //Your logic here (You can Put the OnAttachStateChangeListener here)
 }
});
Dharman
  • 30,962
  • 25
  • 85
  • 135
Dev4Life
  • 2,328
  • 8
  • 22