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 ;
"Binary XML file line #2: Error inflating class android.support.v7.widget.CardView"
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 :)
here is my gradle ;
here is my logcat;
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)
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>
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); }
}
here is my adapter;
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();