libgdx: NullPointerException on AndroidXKeyboardHeightProvider.start on version 1.13.0

Issue details

Hi, after updating from libGDX 1.12.1 to 1.13.0 and published a couple of games some errors have appeared in the Google Play Console and firebase crashlytics:

Exception java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnApplyWindowInsetsListener(android.view.View$OnApplyWindowInsetsListener)' on a null object reference
  at androidx.core.view.ViewCompat$Api21Impl.setOnApplyWindowInsetsListener (ViewCompat.java:4840)
  at androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener (ViewCompat.java:2537)
  at com.badlogic.gdx.backends.android.keyboardheight.AndroidXKeyboardHeightProvider.start (AndroidXKeyboardHeightProvider.java:33)
  at com.badlogic.gdx.backends.android.AndroidApplication$2.run (AndroidApplication.java:298)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:233)
  at android.os.Looper.loop (Looper.java:344)
  at android.app.ActivityThread.main (ActivityThread.java:8248)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:589)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1071)

Reproduction steps/code

This is not happening to all users, just “some” of them, I can’t identify a common pattern… Happens to different device brands and OSs: image

Version of libGDX and/or relevant dependencies

libGDX 1.13.0

Of course I have added on build.gradle file the line: implementation 'androidx.core:core:1.13.1'

And the gradle.properties file has the line: android.useAndroidX=true

Please select the affected platforms

  • [X ] Android
  • iOS
  • HTML/GWT
  • Windows
  • Linux
  • macOS

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (10 by maintainers)

Most upvoted comments

But it is true that only projects using the structure initializeForView(myGame, config); + setContentView(gameView); are afected… all games with banners may crash…

Well, not even that, none of my games crash and I use this same Layout for banners. I wonder if the difference may be you are loading the banner ads before setting the content view.

EDIT Also, as a recommendation, game logic initialization (such as initializing AdMob) should be delayed at least to next frame (or after GDPR consent) to improve startup time and prevent ANRs.

It’s correct, when you use initializeForView you need to call setContentView and pass the Layout