尽管使用了最新版本,但膨胀CardView时出错 [英] Getting error inflating CardView despite of using last version

查看:89
本文介绍了尽管使用了最新版本,但膨胀CardView时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个浪费时间的问题。直到昨天我一直在为我的项目做得很好。昨天早上我开始工作时,遇到了这个问题;

I have a problem which is wasting my time. I was working on my project very well until yesterday. When I started to work last morning I have faced this problem ;

二进制XML文件第2行:错误夸大了类android.support.v7.widget.CardView

"Binary XML file line #2: Error inflating class android.support.v7.widget.CardView"

我突然在Google上搜索,并且看到其他一些人也遇到了。但是关于这些问题的答案不是我的解决方案。它没有解决我的问题。请保存我的一天:)

I have suddennly googled and I have seen that some other people faced either. But answers about these problem is not my solution. It hasnt fixed my problem. Pls save my day :)

这是我的礼物;

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-compat:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:animated-vector-drawable:27.1.1'
implementation 'com.android.support:exifinterface:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//new Lİbrary
implementation 'com.github.mancj:MaterialSearchBar:0.7.6'
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
implementation 'com.cepheuen.elegant-number-button:lib:1.0.2'
implementation 'com.github.jd-alexander:android-flat-button:v1.1'
implementation 'com.stepstone.apprating:app-rating:2.0.0'
implementation 'com.github.andremion:counterfab:1.0.1'
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation 'io.paperdb:paperdb:2.6'
//slider
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'com.daimajia.slider:library:1.1.5@aar'
implementation 'com.android.support:multidex:1.0.3'
//facebook account kit
implementation 'com.facebook.android:facebook-share:4.33.0'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.google.gms:google-services:4.0.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.flaviofaria:kenburnsview:1.0.7'
implementation 'com.github.d-max:spots-dialog:1.1@aar'
implementation 'com.google.android.gms:play-services-places:15.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.firebaseui:firebase-ui-auth:3.3.1'
implementation 'com.firebaseui:firebase-ui-database:3.3.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'}

这是我的日志;

 Process: com.orderfood.teknomerkez.orderfood, PID: 14852
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.v7.widget.CardView
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v7.widget.CardView
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
    at android.view.LayoutInflater.createView(LayoutInflater.java:647)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at com.orderfood.teknomerkez.orderfood.Home$5.onCreateViewHolder(Home.java:277)
    at com.orderfood.teknomerkez.orderfood.Home$5.onCreateViewHolder(Home.java:272)

这是我的xml文件;

Here is my xml file;

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    app:cardElevation="4dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.flaviofaria.kenburnsview.KenBurnsView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/backround_main_page"
            android:id="@+id/menu_image"
            android:scaleType="centerCrop" />

        <TextView
            android:fontFamily="@font/fondamento"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/menu_name"
            android:text="Menu Name"
            android:textColor="@color/white"
            android:background="#4f0e0d0e"
            android:textSize="20sp"
            android:gravity="center"
            android:layout_alignParentBottom="true" />
    </RelativeLayout>
</android.support.v7.widget.CardView>

这是我的viewHolder;

here is my viewHolder;

public class MenuViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

public TextView txtMenuName;
public KenBurnsView menu_image;
private ItemClickListener itemClickListener;

public MenuViewHolder(View itemView) {
    super(itemView);
    txtMenuName = itemView.findViewById(R.id.menu_name);
    menu_image = itemView.findViewById(R.id.menu_image);
    itemView.setOnClickListener(this);
}

public void setItemClickListener(ItemClickListener itemClickListener) {
    this.itemClickListener = itemClickListener;
}

@Override
public void onClick(View view) {
itemClickListener.onClick(view,getAdapterPosition(),false);
}

}

这是我的适配器;

Query query = FirebaseDatabase.getInstance()
            .getReference().child("Category");
    FirebaseRecyclerOptions<Category> options = new FirebaseRecyclerOptions.Builder<Category>().setQuery(query, Category.class).build();
    adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {
        @NonNull
        @Override
        public MenuViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.menu_item, parent, false);
            return new MenuViewHolder(view);
        }

        @Override
        protected void onBindViewHolder(@NonNull MenuViewHolder viewHolder, int position, @NonNull Category model) {
            viewHolder.txtMenuName.setText(model.getName());
            Picasso p = Picasso.get();
            p.load(model.image).into(viewHolder.menu_image);

            final Category clickItem = model;
            viewHolder.setItemClickListener(new ItemClickListener() {
                @Override
                public void onClick(View view, int position, boolean isLongClick) {
                    Toast.makeText(Home.this, "" + clickItem.getName(), Toast.LENGTH_SHORT).show();
                    Intent food_intent = new Intent(Home.this, FoodList.class);
                    //Because categoryId is key , so we just get key of this item
                    food_intent.putExtra(getCategoryId, adapter.getRef(position).getKey());
                    food_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(food_intent);
                }
            });
        }
    };
  adapter.startListening();


推荐答案

删除xml中的起始空间。 <?xml version = 1.0 encoding = utf-8?>
原因:Xml声明应位于所有文档内容之前。

Remove that starting space in your xml.(Just before <?xml version="1.0" encoding="utf-8"?>) Reason: Xml declaration should precede all document content.

这篇关于尽管使用了最新版本,但膨胀CardView时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆