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

问题描述

我在尝试运行我的应用程序时意外遇到以下错误:

I unexpectedly encountered the following error while trying to run my application:

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

以下是日志猫:

11-09 13:11:58.558: E/AndroidRuntime(12542): FATAL EXCEPTION: main
    11-09 13:11:58.558: E/AndroidRuntime(12542): android.view.InflateException: Binary XML file line #8: Error inflating class android.support.v7.widget.CardView
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at com.dooba.beta.ThirdFragment.onCreateView(ThirdFragment.java:15)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.os.Handler.handleCallback(Handler.java:615)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.os.Handler.dispatchMessage(Handler.java:92)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.os.Looper.loop(Looper.java:137)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.app.ActivityThread.main(ActivityThread.java:4745)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at java.lang.reflect.Method.invokeNative(Native Method)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at java.lang.reflect.Method.invoke(Method.java:511)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at dalvik.system.NativeStart.main(Native Method)
    11-09 13:11:58.558: E/AndroidRuntime(12542): Caused by: java.lang.ClassNotFoundException: android.support.v7.widget.CardView
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.view.LayoutInflater.createView(LayoutInflater.java:552)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
    11-09 13:11:58.558: E/AndroidRuntime(12542):    ... 19 more

以下是java代码:

public class ThirdFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.activity_city, container, false);

        return rootView;
    }


}

以下是布局代码:

<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"
        android:layout_width="match_parent"
    android:layout_height="match_parent"
   >
    <!-- 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"
       >

        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            />
    </android.support.v7.widget.CardView>
</LinearLayout>

提前致谢

推荐答案

我通过在app / build.gradle上添加更新的cardview和appcompat解决了这个问题

I solved this by adding updated cardview and appcompat on the app/build.gradle

dependencies {
    ...
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:cardview-v7:23.4.0'
    compile 'com.android.support:recyclerview-v7:23.4.0'
    }

然后重建项目

这篇关于扩展类android.support.v7.widget.CardView时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:08