NPE for application context in ProducerFactory on initialization
Caused by: java.lang.NullPointerException
at android.app.ContextImpl.getAssets(ContextImpl.java:943)
at android.content.ContextWrapper.getAssets(ContextWrapper.java:83)
at com.facebook.imagepipeline.core.ProducerFactory.<init>(ProducerFactory.java:99)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getProducerFactory(ImagePipelineFactory.java:189)
We need more details. What Android version? You coudl also look up in the Android source yourself and see what is null on ContextImpl.java:943
@Override
public AssetManager getAssets() {
return getResources().getAssets();
}
@Override
public Resources getResources() {
return mResources;
}
Maybe mResources return null.but,fresco is initialized in the onCreate function,resource should not be empty
Can you please provide the full stack trace?
java.lang.RuntimeException: Unable to start receiver com.droidwolf.sdk.push.VipsPushReceiver: java.lang.RuntimeException: Unable to create application com.achievo.droidwolf.common.BaseApplication: java.lang.NullPointerException
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2429)
at android.app.ActivityThread.access$1700(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5050)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:805)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.RuntimeException: Unable to create application com.achievo.droidwolf.common.BaseApplication: java.lang.NullPointerException
at android.app.LoadedApk.makeApplication(LoadedApk.java:531)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2409)
at android.app.ActivityThread.access$1700(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5050)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:805)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.NullPointerException
at android.app.ContextImpl.getAssets(ContextImpl.java:633)
at android.content.ContextWrapper.getAssets(ContextWrapper.java:83)
at com.facebook.imagepipeline.core.ProducerFactory.<init>(ProducerFactory.java:99)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getProducerFactory(ImagePipelineFactory.java:189)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getProducerSequenceFactory(ImagePipelineFactory.java:209)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getImagePipeline(ImagePipelineFactory.java:175)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.<init>(PipelineDraweeControllerBuilderSupplier.java:46)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.<init>(PipelineDraweeControllerBuilderSupplier.java:38)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.<init>(PipelineDraweeControllerBuilderSupplier.java:32)
at com.facebook.drawee.backends.pipeline.Fresco.initializeDrawee(Fresco.java:43)
at com.facebook.drawee.backends.pipeline.Fresco.initialize(Fresco.java:39)
at com.achievo.droidwolf.common.BaseApplication.onCreate(BaseApplication.java:470)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at com.lbe.security.service.core.client.b.x.callApplicationOnCreate()
at android.app.LoadedApk.makeApplication(LoadedApk.java:528)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2409)
at android.app.ActivityThread.access$1700(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5050)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:805)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)
at dalvik.system.NativeStart.main(NativeStart.java)
4.2.2 ANDROID VERSION、No ROOTED、DEVICE:"Coolpad 7295C" or 'HM NOTE 1LTETD"
Got the same error, Frsco is initialized in Application class
Caused by: java.lang.NullPointerException
at android.app.ContextImpl.getAssets(ContextImpl.java:714)
at android.content.ContextWrapper.getAssets(ContextWrapper.java:83)
at com.facebook.imagepipeline.core.ProducerFactory.(SourceFile:97)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getProducerFactory(SourceFile:186)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getProducerSequenceFactory(SourceFile:206)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getImagePipeline(SourceFile:172)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.(SourceFile:46)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.(SourceFile:38)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.(SourceFile:32)
at com.facebook.drawee.backends.pipeline.Fresco.initializeDrawee(SourceFile:43)
at com.facebook.drawee.backends.pipeline.Fresco.initialize(SourceFile:39)
at com.app.wooplr.Global.initializeFresco(SourceFile:184)
at com.app.wooplr.Global.onCreate(SourceFile:170)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.LoadedApk.makeApplication(LoadedApk.java:530)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2436)
at android.app.ActivityThread.access$800(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5398)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:940)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
at dalvik.system.NativeStart.main(NativeStart.java)
Any update about it?
Same error:
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetManager android.content.res.Resources.getAssets()' on a null object reference
at android.app.ContextImpl.getAssets(ContextImpl.java:793)
at android.content.ContextWrapper.getAssets(ContextWrapper.java:80)
at com.facebook.imagepipeline.core.ProducerFactory.<init>(ProducerFactory.java:102)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getProducerFactory(ImagePipelineFactory.java:269)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getProducerSequenceFactory(ImagePipelineFactory.java:291)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getImagePipeline(ImagePipelineFactory.java:229)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.<init>(PipelineDraweeControllerBuilderSupplier.java:46)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.<init>(PipelineDraweeControllerBuilderSupplier.java:38)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.<init>(PipelineDraweeControllerBuilderSupplier.java:32)
at com.facebook.drawee.backends.pipeline.Fresco.initializeDrawee(Fresco.java:43)
at com.facebook.drawee.backends.pipeline.Fresco.initialize(Fresco.java:33)
at com.hostelworld.app.Application.onApplicationCreate(Application.java:20)
at com.ad4screen.sdk.A4SApplication.onCreate(SourceFile:25)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
at android.app.LoadedApk.makeApplication(LoadedApk.java:579)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2651)
at android.app.ActivityThread.access$1700(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1428)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5373)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
Initialised in Application class:
sContext = getApplicationContext();
ImagePipelineConfig config = OkHttpImagePipelineConfigFactory
.newBuilder(sContext, new OkHttpClient())
.build();
Fresco.initialize(sContext, config);
Device info (None of these devices is rooted):
SHV-E210K - 4.1.2 HTC One X+ - 4.2.2 GT-I9300 - 4.3 SM-G386T - 4.4.2 SM-T310 - 4.4.2 SM-G906L - 4.4.2 D6603 - 5.1.1 D5833 - 5.1.1
I got a same problem
It seems that the application context is not initialized yet (mBaseContext is still null). @droidwolf: where are you doing this initialization code? Can you check two things?
- sContext.getApplicationContext() is not null
- sContext.getBaseContext() is not null
I think this might be because the Application si not initialized yet: see the analysis here: http://stackoverflow.com/questions/24883903/when-is-getapplicationcontext-of-application-class-called
in Application.onCreate function
After calling super? Also: can you check this two things?
- sContext.getApplicationContext() is not null
- sContext.getBaseContext() is not null
I'm also getting NPE, and it seems that happens while the application is being created after my GCM receiver is started.
Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.yopapp.yop.receivers.GcmBroadcastReceiver: java.lang.RuntimeException: Unable to create application com.yopapp.yop.YopApplication: java.lang.NullPointerException
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2291)
at android.app.ActivityThread.access$1600(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4960)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.RuntimeException: Unable to create application com.yopapp.yop.YopApplication: java.lang.NullPointerException
at android.app.LoadedApk.makeApplication(LoadedApk.java:514)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2271)
at android.app.ActivityThread.access$1600(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4960)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.NullPointerException
at android.app.ContextImpl.getAssets(ContextImpl.java:620)
at android.content.ContextWrapper.getAssets(ContextWrapper.java:75)
at com.facebook.imagepipeline.core.ProducerFactory.(ProducerFactory.java)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getProducerFactory(ImagePipelineFactory.java:394)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getProducerSequenceFactory(ImagePipelineFactory.java:417)
at com.facebook.imagepipeline.core.ImagePipelineFactory.getImagePipeline(ImagePipelineFactory.java:312)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.(PipelineDraweeControllerBuilderSupplier.java)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.(PipelineDraweeControllerBuilderSupplier.java)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier.(PipelineDraweeControllerBuilderSupplier.java)
at com.facebook.drawee.backends.pipeline.Fresco.initializeDrawee(Fresco.java:43)
at com.facebook.drawee.backends.pipeline.Fresco.initialize(Fresco.java:33)
at com.yopapp.yop.YopApplication.onCreate(YopApplication.java:27)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2271)
at android.app.ActivityThread.access$1600(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4960)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(NativeStart.java)
Closing as there has been no further reports of this since 2016