当前位置: 首页 > 知识库问答 >
问题:

Android-inflating类com.facebook.drawee.view.SimpleDraweeView异常错误

子车劲
2023-03-14

我在Play Store上发布了我的应用程序,在我的测试中没有任何错误,但是我从Firebase收到的报告显示我的适配器存在一些问题,跟踪错误和代码:

Exception android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.facebook.drawee.view.SimpleDraweeView
android.view.LayoutInflater.inflate (LayoutInflater.java:539)
android.view.LayoutInflater.inflate (LayoutInflater.java:423)
br.com.topimagens.topimagens.adapters.ImageAdapter.onCreateViewHolder (ImageAdapter.java:85)
br.com.topimagens.topimagens.adapters.ImageAdapter.onCreateViewHolder (ImageAdapter.java:51)
android.support.v7.widget.RecyclerView$Adapter.createViewHolder (RecyclerView.java:5779)
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5003)
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:4913)
android.support.v7.widget.LinearLayoutManager$LayoutState.next (LinearLayoutManager.java:2029)
android.support.v7.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1414)
android.support.v7.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1377)
android.support.v7.widget.LinearLayoutManager.onLayoutChildren (LinearLayoutManager.java:578)
android.support.v7.widget.RecyclerView.dispatchLayoutStep2 (RecyclerView.java:3260)
android.support.v7.widget.RecyclerView.dispatchLayout (RecyclerView.java:3069)
android.support.v7.widget.RecyclerView.onLayout (RecyclerView.java:3518)
android.view.View.layout (View.java:16646)
android.view.ViewGroup.layout (ViewGroup.java:5440)
android.support.design.widget.HeaderScrollingViewBehavior.layoutChild (HeaderScrollingViewBehavior.java:131)
android.support.design.widget.ViewOffsetBehavior.onLayoutChild (ViewOffsetBehavior.java:42)
android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild (AppBarLayout.java:1319)
android.support.design.widget.CoordinatorLayout.onLayout (CoordinatorLayout.java:817)
android.view.View.layout (View.java:16646)
android.view.ViewGroup.layout (ViewGroup.java:5440)
android.widget.RelativeLayout.onLayout (RelativeLayout.java:1079)
android.view.View.layout (View.java:16646)
android.view.ViewGroup.layout (ViewGroup.java:5440)
android.widget.FrameLayout.layoutChildren (FrameLayout.java:336)
android.widget.FrameLayout.onLayout (FrameLayout.java:273)
android.view.View.layout (View.java:16646)
android.view.ViewGroup.layout (ViewGroup.java:5440)
android.widget.LinearLayout.setChildFrame (LinearLayout.java:1743)
android.widget.LinearLayout.layoutVertical (LinearLayout.java:1586)
android.widget.LinearLayout.onLayout (LinearLayout.java:1495)
android.view.View.layout (View.java:16646)
android.view.ViewGroup.layout (ViewGroup.java:5440)
android.widget.FrameLayout.layoutChildren (FrameLayout.java:336)
android.widget.FrameLayout.onLayout (FrameLayout.java:273)
android.view.View.layout (View.java:16646)
android.view.ViewGroup.layout (ViewGroup.java:5440)
android.widget.LinearLayout.setChildFrame (LinearLayout.java:1743)
android.widget.LinearLayout.layoutVertical (LinearLayout.java:1586)
android.widget.LinearLayout.onLayout (LinearLayout.java:1495)
android.view.View.layout (View.java:16646)
android.view.ViewGroup.layout (ViewGroup.java:5440)
android.widget.FrameLayout.layoutChildren (FrameLayout.java:336)
android.widget.FrameLayout.onLayout (FrameLayout.java:273)
com.android.internal.policy.PhoneWindow$DecorView.onLayout (PhoneWindow.java:2678)
android.view.View.layout (View.java:16646)
android.view.ViewGroup.layout (ViewGroup.java:5440)
android.view.ViewRootImpl.performLayout (ViewRootImpl.java:2183)
android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:1943)
android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1119)
android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:6060)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:858)
android.view.Choreographer.doCallbacks (Choreographer.java:670)
android.view.Choreographer.doFrame (Choreographer.java:606)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:844)
android.os.Handler.handleCallback (Handler.java:746)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:148)
android.app.ActivityThread.main (ActivityThread.java:5443)
public ImageAdapter(Context c, List<Image> l){
    this(c, l, true, true);
}
public ImageAdapter(Context c, List<Image> l, boolean wa, boolean wcl){
    mContext = c;
    mList = l;
    mLayoutInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    sharedPreference = new SharedPreference();

    withAnimation = wa;
    withImagedLayout = wcl;

    scale = mContext.getResources().getDisplayMetrics().density;
    width = mContext.getResources().getDisplayMetrics().widthPixels - (int)(14 * scale + 0.5f);

    roundPixels = (int)(2 * scale + 0.5f);

}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    View v;
    MyViewHolder mvh;
        v = mLayoutInflater.inflate(R.layout.item_image_card, viewGroup, false);
        mvh = new MyViewHolder(v);
        v.setTag(viewGroup);


    return mvh;
}

@Override
public void onBindViewHolder(final MyViewHolder myViewHolder, int position) {

    myViewHolder.tvTitulo.setText(mList.get(position).getTitulo());

    Image image = getItem(position);
    myViewHolder.tvTitulo.setText(image.getTitulo());
    myViewHolder.tvTitulo.setText(image.getTitulo());

    if (checkFavoriteItem(image)) {
        myViewHolder.ivMenuFavorite.setImageResource(R.drawable.ico_heart_on);
        myViewHolder.ivMenuFavorite.setTag("red");
       // Log.e("Result: ", "red" );
    } else {
        myViewHolder.ivMenuFavorite.setImageResource(R.drawable.ico_heart_off);
        myViewHolder.ivMenuFavorite.setTag("grey");
        //Log.e("Result: ", "grey" );
    }

    ControllerListener listener = new BaseControllerListener(){
        @Override
        public void onFinalImageSet(String id, Object imageInfo, Animatable animatable) {
            super.onFinalImageSet(id, imageInfo, animatable);
            updateViewSize((ImageInfo) imageInfo);
        }

        @Override
        public void onFailure(String id, Throwable throwable) {
            super.onFailure(id, throwable);
        }

        @Override
        public void onIntermediateImageFailed(String id, Throwable throwable) {
            super.onIntermediateImageFailed(id, throwable);
        }

        @Override
        public void onIntermediateImageSet(String id, Object imageInfo) {
            super.onIntermediateImageSet(id, imageInfo);
            updateViewSize((ImageInfo) imageInfo);
        }

        @Override
        public void onRelease(String id) {
            super.onRelease(id);
        }

        @Override
        public void onSubmit(String id, Object callerContext) {
            super.onSubmit(id, callerContext);
        }

        void updateViewSize(@Nullable ImageInfo imageInfo) {
            if (imageInfo != null) {
                    //myViewHolder.ivImage.getLayoutParams().width = imageInfo.getWidth();
                    myViewHolder.ivImage.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
                    myViewHolder.ivImage.setAspectRatio((float) imageInfo.getWidth() / imageInfo.getHeight());
            }
        }

    };


    ImagePipeline imagePipeline = Fresco.getImagePipeline();

    ImageRequest imageRequest = ImageRequestBuilder
            .newBuilderWithSource(Uri.parse(mList.get(position).getPhoto()))
            .setRequestPriority(Priority.HIGH)
            .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)
            .build();

    DataSource<CloseableReference<CloseableImage>> dataSource =
            imagePipeline.fetchDecodedImage(imageRequest, mContext);

    try {
        dataSource.subscribe(new BaseBitmapDataSubscriber() {
            @Override
            public void onNewResultImpl(@Nullable Bitmap bitmap) {
                if (bitmap == null) {
                    Log.d(TAG, "Bitmap data source returned success, but bitmap null.");
                }

            }

            @Override
            public void onFailureImpl(DataSource dataSource) {
                // No cleanup required here
            }
        }, CallerThreadExecutor.getInstance());
    } finally {
        if (dataSource != null) {
            dataSource.close();
        }
    }

    Uri uri = Uri.parse( mList.get(position).getPhoto() );
    DraweeController dc = Fresco.newDraweeControllerBuilder()
            .setUri( uri )
            .setTapToRetryEnabled(true)
            .setControllerListener( listener )
            .setOldController( myViewHolder.ivImage.getController() )
            .build();

    RoundingParams rp = RoundingParams.fromCornersRadii(roundPixels, roundPixels, 0, 0);
    myViewHolder.ivImage.setController(dc);
    myViewHolder.ivImage.getHierarchy().setRoundingParams( rp );

    if(withAnimation){
        try{
            YoYo.with(Techniques.ZoomIn)
                    .duration(700)
                    .playOn(myViewHolder.itemView);
        }
        catch(Exception e){}
    }

}

public Image getItem(int position) {
    return mList.get(position);
}

public int getItemCount() {
    return null!=mList?mList.size():0;
}

public void addListItem(Image c, int position){
    mList.add(position, c);
    notifyItemInserted(position);
}


public void removeListItem(int position){
    mList.remove(position);
    notifyItemRemoved(position);
}

public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
    public SimpleDraweeView ivImage;
    public TextView tvTitulo;
    public TextView ivContextMenuWhats;
    public TextView ivContextMenuFace;
    public TextView ivContextMenuShare;
    public ImageView ivMenuFavorite;


    public MyViewHolder(View itemView) {
        super(itemView);
        //int position =  (int) itemView.getTag();
        ivImage = (SimpleDraweeView) itemView.findViewById(R.id.iv_image);
        tvTitulo = (TextView) itemView.findViewById(R.id.tv_titulo);
        ivContextMenuWhats = (TextView) itemView.findViewById(R.id.iv_buttom_whats);
        ivContextMenuFace = (TextView) itemView.findViewById(R.id.iv_buttom_face);
        ivContextMenuShare = (TextView) itemView.findViewById(R.id.iv_buttom_share);
        ivMenuFavorite = (ImageView) itemView.findViewById(R.id.iv_buttom_favorite);


        if( ivContextMenuWhats != null ){
            ivContextMenuWhats.setOnClickListener(this);
        }
        if( ivContextMenuFace != null ){
            ivContextMenuFace.setOnClickListener(this);
        }
        if( ivContextMenuShare != null ){
            ivContextMenuShare.setOnClickListener(this);
        }
        if( ivMenuFavorite != null ){
            ivMenuFavorite.setOnClickListener(this);
        }

    }


    public void onClick(View v) {

        Image image = mList.get(getAdapterPosition());
        String tag = ivMenuFavorite.getTag().toString();

        switch (v.getId()) {
            case R.id.iv_buttom_whats: {
                FirebaseCrash.log("ImageAdapter:onClick:iv_buttom_whats");
                if (isPackageInstalled("com.whatsapp")) {
                    new MyAsyncTask(mContext, mList.get(getAdapterPosition()).getFoto(), mList.get(getAdapterPosition()).getPhoto(), "com.whatsapp").execute();
                } else {
                    Toast.makeText(mContext, mContext.getString(R.string.txt_whatsapp_not_faund), Toast.LENGTH_SHORT).show();
                }
                break;
            }

            case R.id.iv_buttom_face: {
                FirebaseCrash.log("ImageAdapter:onClick:iv_buttom_face");
                if (isPackageInstalled("com.facebook.katana")) {
                    new MyAsyncTask(mContext, mList.get(getAdapterPosition()).getFoto(), mList.get(getAdapterPosition()).getPhoto(), "com.facebook.katana").execute();
                } else {
                    Toast.makeText(mContext, mContext.getString(R.string.txt_facebook_not_faund), Toast.LENGTH_SHORT).show();
                }
                break;
            }

            case R.id.iv_buttom_share: {
                FirebaseCrash.log("ImageAdapter:onClick:iv_buttom_share");
                new MyAsyncTask(mContext, mList.get(getAdapterPosition()).getFoto(), mList.get(getAdapterPosition()).getPhoto(), "share").execute();
                break;
            }
            case R.id.iv_buttom_favorite: {
                FirebaseCrash.log("ImageAdapter:onClick:iv_buttom_favorite");
            if (tag.equalsIgnoreCase("grey")) {
                sharedPreference.addFavorite(mContext, image);
                Toast.makeText(mContext,
                mContext.getResources().getString(R.string.txt_favorite_add),
                Toast.LENGTH_SHORT).show();
                //Toast.makeText(mContext, image.toString(), Toast.LENGTH_LONG).show();
                //Log.e("Cor red", tag);
                ivMenuFavorite.setTag("red");
                ivMenuFavorite.setImageResource(R.drawable.ico_heart_on);
            } else {
                sharedPreference.removeFavorite(mContext, image);
                ivMenuFavorite.setTag("grey");
                ivMenuFavorite.setImageResource(R.drawable.ico_heart_off);
                // Toast.makeText(mContext, "remove" + qid ,Toast.LENGTH_SHORT).show();
                Toast.makeText(mContext,
                mContext.getResources().getString(R.string.txt_remove_favorite),
                Toast.LENGTH_SHORT).show();
                //Log.e("Cor grey", tag);
            }

                break;
            }
        }
    }


    public boolean isPackageInstalled(String packagename) {
        PackageManager pm = mContext.getPackageManager();
        try {
            pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
            return true;
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }
}

public boolean checkFavoriteItem(Image checkImage) {
    boolean check = false;
    List<Image> myList = sharedPreference.getFavorites(mContext);
    if (myList != null) {
        for (Image image : myList) {
            if (image.equals(checkImage)) {
                check = true;

                break;
            }
        }            
    }
    return check;
}
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f8f8f8">

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/iv_image"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_alignParentTop="true"
        fresco:actualImageScaleType="center"
        fresco:failureImage="@drawable/error_img"
        fresco:placeholderImage="@drawable/loading_img"
        fresco:retryImage="@drawable/retry_img" />

    <TextView
        android:id="@+id/tv_titulo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#f8f8f8"
        android:layout_below="@+id/iv_image"
        android:padding="8dp"
        android:textColor="@color/colorPrimarytext"
        android:textSize="14sp" />

    <TextView
        android:textSize="12sp"
        android:textStyle="bold"
        android:textColor="#fff"
        android:ellipsize="marquee"
        android:gravity="top|bottom|center_vertical|fill_vertical|center|fill"
        android:id="@+id/iv_buttom_whats"
        android:background="@drawable/border_corner"
        android:paddingBottom="8dp"
        android:padding="8dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/compartilhar_no_whatsapp"
        android:singleLine="true"
        android:drawableLeft="@drawable/ic_whatsapp_white"
        android:drawablePadding="8dp"
        android:marqueeRepeatLimit="marquee_forever"
        android:layout_below="@+id/tv_titulo"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp" />

    <TextView
        android:textSize="12sp"
        android:textStyle="bold"
        android:textColor="#fff"
        android:ellipsize="marquee"
        android:gravity="top|bottom|center_vertical|fill_vertical|center|fill"
        android:id="@+id/iv_buttom_face"
        android:background="@drawable/border_corner_face"
        android:padding="8dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:drawableLeft="@drawable/ic_facebook_white"
        android:drawablePadding="8dp"
        android:marqueeRepeatLimit="marquee_forever"
        android:layout_below="@+id/tv_titulo"
        android:layout_toRightOf="@+id/iv_buttom_whats"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp" />

    <TextView
        android:textSize="12sp"
        android:textStyle="bold"
        android:textColor="#fff"
        android:ellipsize="marquee"
        android:gravity="top|bottom|center_vertical|fill_vertical|center|fill"
        android:id="@+id/iv_buttom_share"
        android:background="@drawable/border_corner_share"
        android:padding="8dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:drawableLeft="@drawable/ic_share_white"
        android:drawablePadding="8dp"
        android:marqueeRepeatLimit="marquee_forever"
        android:layout_below="@+id/tv_titulo"
        android:layout_toRightOf="@+id/iv_buttom_face"
        android:layout_toEndOf="@+id/iv_buttom_face"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp" />

    <ImageView
        android:textSize="12sp"
        android:textStyle="bold"
        android:textColor="#fff"
        android:ellipsize="marquee"
        android:gravity="top|bottom|center_vertical|fill_vertical|center|fill"
        android:id="@+id/iv_buttom_favorite"
        android:padding="8dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:background="@null"
        android:drawablePadding="8dp"
        android:marqueeRepeatLimit="marquee_forever"
        android:layout_below="@+id/tv_titulo"
        android:layout_toRightOf="@+id/iv_buttom_share"
        android:layout_toEndOf="@+id/iv_buttom_share"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:contentDescription="@string/favorites"
        android:clickable="true" />

    <Space
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_below="@+id/iv_buttom_whats"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

我感谢任何能帮助我的人

共有1个答案

符棋
2023-03-14

您必须调用fresco.initialize(...)。在自定义application类中只执行一次此操作。更多信息见http://frescolib.org/docs/index.html。

如果这不能解决问题,可能是ProGuard没有正确设置。如何使用Fresco设置ProGuard:http://frescolib.org/docs/ProGuard.html

 类似资料:
  • 我正在写一个android应用程序,其中包括一个谷歌地图片段。当我将地图片段从包含它的活动中排除时,应用程序运行良好。当我包含映射片段时,我会得到下面blockquote中引用的异常。最让人恼火的是,就在几周前,这还没有发生。这个活动运行了几个星期,然后我更新了android studio,现在我得到了这个例外。我已经在google和stackoverflow上搜索了几个解决方案,但没有任何效果。

  • 下午好,我想解决一个问题,但我不能。我有两部智能手机,一部Nexus 5(Android 6.0)和一部ZenFone 2(Android 5.0)。该错误仅在ZenFone中持续存在。 XML: Android.View.InflateException:二进制XML文件行#25:在Android.View.LayoutInflater.CreateViewFromTag(LayoutInfla

  • 当我想启动我的应用程序时,我得到的错误“应用程序已经停止工作。为什么我得到这个错误,当我启动应用程序?

  • 我得到了一个错误,这是我的XML文件 这里是styles.xml 我尝试将AppCompat更改为MaterialComponents,但它不起作用。但是当我指向LinearLayout标记(com.google.android.Material.TextField.TextInputLayout的父标记)时,它会用红线显示错误,当我移除LinearLayout标记时,它会消失。当我使用太多的Li

  • 我对Android开发真的是一个新手,有几天我会尝试在我的应用程序中添加一个地图。我尝试了一些事情,但没有成功。如果有人能帮我,我很感激。 我做过的事: 将google-play-services_lib添加到我的包资源管理器中。 包含了android-support-v4.jar和google-play-services.jar作为我的项目的依赖项。 下面是main.xml文件 这里是清单文件