exception:android.view.InflateException:二进制XML文件行#2:错误膨胀类android.support.v7.widget.CardView

我在我的android应用程序中使用CardView的支持库。 我尝试了4-5个小时来解决这个问题,但我无法取得成功。

我还在我的项目&v7 appcompat中添加了CardView作为库

 <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="match_parent" android:layout_margin="5dp" android:orientation="horizontal" app:cardCornerRadius="4dp" > 

但我的应用程序崩溃与日志下面

 10-31 18:41:39.577: E/AndroidRuntime(5666): FATAL EXCEPTION: main 10-31 18:41:39.577: E/AndroidRuntime(5666): Process: com.xyzladdoo, PID: 5666 10-31 18:41:39.577: E/AndroidRuntime(5666): android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v7.widget.CardView 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 10-31 18:41:39.577: E/AndroidRuntime(5666): at com.xyzladdoo.adapters.RecycleViewAdapter.onCreateViewHolder(RecycleViewAdapter.java:85) 10-31 18:41:39.577: E/AndroidRuntime(5666): at com.xyzladdoo.adapters.RecycleViewAdapter.onCreateViewHolder(RecycleViewAdapter.java:1) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:2915) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:2511) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.support.v7.widget.LinearLayoutManager$RenderState.next(LinearLayoutManager.java:1425) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:999) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:524) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:1461) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:1600) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.View.layout(View.java:14860) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewGroup.layout(ViewGroup.java:4643) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:543) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.View.layout(View.java:14860) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewGroup.layout(ViewGroup.java:4643) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.View.layout(View.java:14860) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewGroup.layout(ViewGroup.java:4643) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.View.layout(View.java:14860) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewGroup.layout(ViewGroup.java:4643) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1594) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.View.layout(View.java:14860) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewGroup.layout(ViewGroup.java:4643) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:887) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.View.layout(View.java:14860) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewGroup.layout(ViewGroup.java:4643) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.View.layout(View.java:14860) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewGroup.layout(ViewGroup.java:4643) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.support.v7.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:502) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.View.layout(View.java:14860) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewGroup.layout(ViewGroup.java:4643) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.View.layout(View.java:14860) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewGroup.layout(ViewGroup.java:4643) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.View.layout(View.java:14860) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewGroup.layout(ViewGroup.java:4643) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.View.layout(View.java:14860) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewGroup.layout(ViewGroup.java:4643) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2013) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1770) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1019) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5725) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.Choreographer.doCallbacks(Choreographer.java:574) 10-31 18:41:39.577: E/AndroidRuntime(5666): at android.view.Choreographer.doFrame(Choreographer.java:544) 10-31 18:41:39.577: E/AndroidRuntime(5666): at an 

任何帮助? 提前致谢。

Solutions Collecting From Web of "exception:android.view.InflateException:二进制XML文件行#2:错误膨胀类android.support.v7.widget.CardView"

让Cardview作为一个库导入:
转到文件 – >导入 – >现有的Android代码到工作区 – >浏览(转到SDK /附加/安卓/支持/ V7 / CardView) – >点击确定 – >点击完成

您的项目浏览器现在将cardview显示为一个项目。

右键点击cardview项目 – >属性 – > Android(左窗格) – >启用isLibrary(勾选checkbox) – >应用 – >确定

现在右键点击你的项目 – >属性 – > Android(左窗格) – >添加(在库下) – > cardview – >应用 – >确定

现在再次右键单击你的项目 – >构buildpath – >configuration构buildpath – >在项目选项卡下,添加cardview

你完成了。
资源

(对于intellij用户)

  • 点击你的项目,
  • 右键单击 – >打开模块设置
  • 从\ sdk \ extras \ android \ support \ v7 \
  • 将.jar文件添加到cardview模块
  • 点击你的项目,并给cardview模块依赖
  • 现在,点击cardview – > android – >顶部的(+)button,你会看到一个checkbox(库模块),启用它。
  • 点击确定并closures你的设置对话框。
  • 重build你的项目并运行它。

支持包含编译类(比如XML)以外的资源的库不能像jar子一样添加。

请按照以下步骤操作:

https://developer.android.com/tools/support-library/setup.html#libs-with-res

现在让我们来看看是否有效。

解决这个问题。 首先,您必须从\ sdk \ extras \ android \ support中添加cardview

  1. closures主项目。
  2. 删除android-support-v7-appcompat。
  3. 重新启动Eclipse。
  4. 添加android-support-v7-appcompat。
  5. 清洁,build立项目。
  6. 然后打开主项目并构build所有项目。
  7. 错误仍然存​​在。 重新开启eclipse。 而已。

这对我行得通。

尝试这个..

 <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_gravity="center" android:layout_width="200dp" android:layout_height="200dp" card_view:cardCornerRadius="4dp"> </android.support.v7.widget.CardView> 

参考 : 创build卡片

尝试像这样使用外线性布局。

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:card_view="http://schemas.android.com/apk/res-auto" ... > <!-- A CardView that contains a TextView --> <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_gravity="center" android:layout_width="200dp" android:layout_height="200dp" card_view:cardCornerRadius="4dp"> <TextView android:id="@+id/info_text" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.v7.widget.CardView> </LinearLayout> 

我和你有同样的问题。

Eclipse中 ,当从\ sdk \ extras \ android \ support \ v7 \ cardview目录中导入cardview时,请按照官方文档“ https://developer.android ”中的“使用资源添加库 – > Eclipse”中的注释步骤进行操作。 COM /国际/ ES /工具/支持库/ setup.html#库,与清晰度

在将cardview作为库添加到项目之前,请转到cardview项目的 “属性 – > Android”,然后添加android-support-v7-appcompat库。 不要忘记检查“IsLibrary”。

现在,您可以将cardview作为库添加到您的项目中。 清理两个项目以刷新更改。

我希望它可以帮助你。