错误充气类android.support.v7.widget.CardView [英] Error inflating class and android.support.v7.widget.CardView

查看:1776
本文介绍了错误充气类android.support.v7.widget.CardView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用CardView在我的项目,但是当我跑我的应用程序,我碰到下面的错误。我使用的Eclipse

I want to use CardView in my project, but when I run my application, I get the following error. I'm using Eclipse.

Error: Error inflating class and android.support.v7.widget.CardView

The graphical view of my xml file says 'The following classes could not be instantiated:
- android.support.v7.widget.CardView (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.'

请帮忙。

这是我已经用了我的片段布局 CardView

This is the layout for my fragment where I have used CardView

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.log.MyContactsFragment" >

<!-- TODO: Update blank fragment layout -->

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cvContactDetails"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_gravity="center"
    android:background="?android:attr/selectableItemBackground"
    android:clickable="false"
    android:elevation="20dp" >

    <TextView
        android:id="@+id/tvContacts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Contact Info" />

    <Button
        android:id="@+id/bDelete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Delete" />

    <Button
        android:id="@+id/bExport"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Export to phone contacts" />
</android.support.v7.widget.CardView>

这是我的活动布局。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/flMainContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </FrameLayout>

    <ListView
        android:id="@+id/lvLeftDrawer"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:alpha="255"
        android:background="#0B2161"
        android:divider="@null"
        android:choiceMode="singleChoice" >
    </ListView>

    <ListView
        android:id="@+id/lvRightDrawer"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        android:alpha="255"
        android:background="#0B2161"
        android:divider="@null"
        android:choiceMode="singleChoice" >
    </ListView>

</android.support.v4.widget.DrawerLayout>

这是我的logcat

This is my logcat

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.log/com.example.log.HomeScreenActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.v7.widget.CardView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.v7.widget.CardView
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.example.log.MyContactsFragment.onCreateView(MyContactsFragment.java:60)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:571)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
at android.app.Activity.performStart(Activity.java:5018)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
25 more
Caused by: java.lang.NoClassDefFoundError: android.support.v7.cardview.R$styleable
at android.support.v7.widget.CardView.initialize(CardView.java:203)
at android.support.v7.widget.CardView.<init>(CardView.java:101)
... 28 more

有人谁也遇到了同样的问题还是解决了这个问题,请评论。

Someone who has encountered the same problem or solved it, please comment.

推荐答案

我想我可以回答我的问题。

I guess I can answer my own question.

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

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.support.v7.widget.CardView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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