Error inflating class com.facebook.drawee.view.SimpleDraweeView
Asked Answered
P

6

8

I'm trying to use the fresco library. I used it before too and it was working, but now, for some reason I get:

Unable to start activity ComponentInfo{com.example.home.template/com.example.home.template.MainActivity}: android.view.InflateException: Binary XML file line #26: Error inflating class com.facebook.drawee.view.SimpleDraweeView

My xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:fresco="http://schemas.android.com/apk/res-auto"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">


<com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/profileImage"
        fresco:actualImageScaleType="centerCrop"
        android:layout_width="200dp"
        android:layout_gravity="center_horizontal"
        android:layout_height="200dp" />
</LinearLayout>

MyApplication:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        FacebookSdk.sdkInitialize(this);
    }
}

I have it in my manifest: android:name=".MyApplication"

The only problem that I'm having is with the draweeview. I can do all of the other stuff such as logging in and taking information.

Pentachlorophenol answered 19/4, 2016 at 16:21 Comment(1)
are you using fresco library?Eraeradiate
E
23

In my case writing Fresco.initialize(this); before setContentView(R.layout.myxml); helped me.

Update:

you have FacebookSdk.sdkInitialize(this); instead of Fresco.initialize(this) in your myapplication

Eraeradiate answered 19/4, 2016 at 16:58 Comment(4)
I tried that too and it isn't working, but now as you can see I have it in MyApplication as suggested in here github.com/facebook/fresco/issues/74Pentachlorophenol
you have FacebookSdk.sdkInitialize(this); instead of Fresco.initialize(this) in you myapplicationEraeradiate
Yes, it's working. Should I keep both, or only one ?Pentachlorophenol
just Fresco.initialize(this) is fineEraeradiate
F
4

I was getting this problem in API 19 devices just because I was using drawable vector as placeholder here

fresco:placeholderImage="@drawable/ic_phone"

After changing to PNG my problem was solved.

Dont forget to initialize it in your App as

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        Fresco.initialize(this)
    }
}

as well as this line in manifest's application

android:name=".App"
Futility answered 5/4, 2019 at 17:11 Comment(0)
N
2

Today I had the same problem. However, I forgot to add the property android:name=".MyApplication" in the AndroidManifest.xml.

Nosebleed answered 12/9, 2017 at 14:53 Comment(0)
N
0

In your Application class write the following line:

Fresco.initialize(this);
Nonparticipating answered 19/12, 2018 at 11:47 Comment(0)
C
0

Make sure that you import the right Fresco library and if you do import other Fresco libraries, make sure the other libraries version number is the same with Fresco core library

Crowe answered 17/9, 2020 at 5:51 Comment(0)
C
0

In my case writing Fresco.initialize(this);

before

setContentView(R.layout.activity_main);

Clergy answered 10/9, 2023 at 22:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.