Sometimes, I get this crash while my app is opening:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.widget.ContentFrameLayout.setDecorPadding(int, int, int, int)' on a null object reference
at androidx.appcompat.app.AppCompatDelegateImpl.applyFixedSizeWindow(AppCompatDelegateImpl.java:1026)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:820)
at androidx.appcompat.app.AppCompatDelegateImpl.onPostCreate(AppCompatDelegateImpl.java:527)
at androidx.appcompat.app.AppCompatActivity.onPostCreate(AppCompatActivity.java:127)
at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1381)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3499)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
As you can see, there's no reference to something in my code in the stack trace so for this reason I'm not able to figure out what the problem is. What could be the cause of this crash?.
In my case, I was getting this error in production when I load the first screen. I also use androidx and no Support Libraries. Some times this crash looks like:
Caused by java.lang.RuntimeException
Window couldn't find content container view ***.onCreate
Unfortunately, I still don't understand what exactly the error is but I found this post. I changed onCreate method to:
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
getWindow().getDecorView();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
}
Just added getWindow().getDecorView(); before super.onCreate(savedInstanceState); and it solved my problem.
I had such a case and found what led to the error. I had added a new library that depended on the UI and initialized it in the Application class.
class App : Application() {
override fun onCreate() {
super.onCreate()
MyNewLibrary.init(this) // I removed this library
}
}
This caused the error. After removing the library, everything was fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With