类com.facebook.drawee.view.SimpleDraweeView出错时出错

时间:2016-04-19 16:21:25

标签: android facebook fresco

我正在尝试使用壁画库。我之前也使用它并且它正在工作,但现在,由于某种原因我得到了:

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

我的xml文件:

<?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);
    }
}

我的清单中有它:android:name=".MyApplication"

我遇到的唯一问题是draweeview。我可以做所有其他的事情,比如登录和获取信息。

5 个答案:

答案 0 :(得分:11)

Fresco.initialize(this);帮助我之前写setContentView(R.layout.myxml);的情况。

<强>更新

您的FacebookSdk.sdkInitialize(this);

中有Fresco.initialize(this)而不是myapplication

答案 1 :(得分:2)

今天我遇到了同样的问题。但是,我忘了在android:name=".MyApplication"

中添加属性AndroidManifest.xml

答案 2 :(得分:0)

在您的Application类中,编写以下行:

Fresco.initialize(this);

答案 3 :(得分:0)

我在API 19设备中遇到此问题,只是因为我在此处使用可绘制矢量作为占位符

fresco:placeholderImage="@drawable/ic_phone"

更改为PNG后,我的问题解决了。

不要忘记在应用中以

对其进行初始化
class App : Application() {
    override fun onCreate() {
        super.onCreate()
        Fresco.initialize(this)
    }
}

以及清单应用程序中的这一行

android:name=".App"

答案 4 :(得分:0)

请确保您导入了正确的Fresco库,并且如果要导入其他Fresco库,请确保其他库的版本号与Fresco核心库相同