app crashes on redmi phone - ZygoteInit$Method nullpointer exception

1.5k Views Asked by At

Android app that I have developed crashes frequently mainly on Redmi phone. Android version 6.0. App crashes at any time with the same error/similar error.

Please help with below error, unable to get why this error is coming every now and then. This is the error stack -

FATAL EXCEPTION: main Process: in.test.coupon, PID: 27695 java.lang.RuntimeException: Unable to start activity ComponentInfo{in.test.coupon/in.test.coupon.activities.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) at android.app.ActivityThread.access$900(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5441) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference at android.content.ContextWrapper.getResources(ContextWrapper.java:87) at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:81) at android.support.v7.app.AppCompatActivity.getResources(AppCompatActivity.java:549) at android.view.Window.getDefaultFeatures(Window.java:1359) at android.view.Window.(Window.java:480) at com.android.internal.policy.PhoneWindow.(PhoneWindow.java:305) at com.android.internal.policy.MiuiPhoneWindow.(MiuiPhoneWindow.java:10) at android.app.Activity.attach(Activity.java:6243) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2357) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)  at android.app.ActivityThread.access$900(ActivityThread.java:153)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5441)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)

1

There are 1 best solutions below

1
On

Seems like you are trying to launch activity in.test.coupon/in.test.coupon.activities.MainActivity from some background thread/task, which keeps running even after your activity is destroyed.

Please make sure to stop all such tasks/ threads in your activity onDestroy() method.