fresco icon indicating copy to clipboard operation
fresco copied to clipboard

NPE for application context in ProducerFactory on initialization

Open gold-duo opened this issue 11 years ago • 13 comments

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)

gold-duo avatar Jul 08 '15 04:07 gold-duo

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

plamenko avatar Jul 08 '15 14:07 plamenko

@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

gold-duo avatar Jul 09 '15 04:07 gold-duo

Can you please provide the full stack trace?

plamenko avatar Jul 10 '15 13:07 plamenko

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)

gold-duo avatar Jul 13 '15 09:07 gold-duo

4.2.2 ANDROID VERSION、No ROOTED、DEVICE:"Coolpad 7295C" or 'HM NOTE 1LTETD"

gold-duo avatar Jul 13 '15 09:07 gold-duo

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)

notsatyarth avatar Sep 22 '15 10:09 notsatyarth

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

dreguerahw avatar Nov 10 '15 14:11 dreguerahw

I got a same problem

kkkkkkirs avatar Feb 03 '16 11:02 kkkkkkirs

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?

  1. sContext.getApplicationContext() is not null
  2. 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

balazsbalazs avatar Feb 04 '16 06:02 balazsbalazs

in Application.onCreate function

gold-duo avatar Feb 04 '16 06:02 gold-duo

After calling super? Also: can you check this two things?

  1. sContext.getApplicationContext() is not null
  2. sContext.getBaseContext() is not null

balazsbalazs avatar Feb 04 '16 07:02 balazsbalazs

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)

sirkuryaki avatar Apr 26 '16 20:04 sirkuryaki

Closing as there has been no further reports of this since 2016

erikandre avatar Jan 16 '18 18:01 erikandre