本文介绍了例外:android.view.InflateException:二进制XML文件中的行#2:错误充气类android.support.v7.widget.CardView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid应用程序中使用支持库 CardView 。我想4-5个小时来解决这一点,但我不能得到成功。

I am using CardView of support library in my android app. I tried 4-5 hours to resolve this but i could not get success.

我已经加入 CardView 在我的项目和放大器的库; V7 appcompat也

I have added CardView as a library in my project & v7 appcompat also

<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" >

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

But my app is crashing with below logs

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

任何帮助吗?先谢谢了。

Any help ? Thanks in advance.

推荐答案

让进口cardview为库:
转到文件 - >导入 - >现有的Andr​​oid code到工作空间 - >浏览(进入SDK /演员/安卓/支持/ V7 / cardview) - >点击确定 - >点击Finish(完成)

Let import cardview as a library:
Go to File -> Import -> Existing Android code into workspace --> Browse (Go to sdk/extras/android/support/v7/cardview) --> Click ok --> Click Finish

您的项目资源管理器现在将显示cardview作为一个项目。

Your project explorer will now show cardview as a project.

右键点击cardview项目 - >属性 - >安卓(左窗格) - >启用isLibrary(打勾的复选框) - >应用 - >确定

Right click on cardview project --> Properties --> Android(Left Pane) --> Enable isLibrary (tick the checkbox) --> Apply --> ok

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

Now Right click on your project --> Properties --> Android(Left pane) --> Add (under library) --> cardview --> apply --> ok

现在右键点击你的项目了 - >构建路径 - >配置构建路径 - >在项目选项卡中,添加cardview

Now right click on your project again --> build path --> configure build path --> Under projects tab, add cardview

您完成。
来源

这篇关于例外:android.view.InflateException:二进制XML文件中的行#2:错误充气类android.support.v7.widget.CardView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 02:12