扩展类android.support.v7.widget.RecyclerView(Eclipse)时出错

时间:2016-09-23 08:19:35

标签: android eclipse gradle android-recyclerview

我想在eclipse的android项目中使用android.support.v7.widget.RecyclerView

$client_name = ($client->first_name !== null || $client->first_name !== '') ? $client->first_name." ".$client->last_name : $client->username;

但它会抛出错误

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="ir.sheikhoo.sis.EditeActivity" >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>

</RelativeLayout>

完整错误日志

09-23 11:33:37.968: E/AndroidRuntime(20310): java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.sheikhoo.sis/ir.sheikhoo.sis.EditeActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.v7.widget.RecyclerView

我使用09-23 11:55:53.288: E/AndroidRuntime(28333): FATAL EXCEPTION: main 09-23 11:55:53.288: E/AndroidRuntime(28333): Process: ir.sheikhoo.sis, PID: 28333 09-23 11:55:53.288: E/AndroidRuntime(28333): java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.sheikhoo.sis/ir.sheikhoo.sis.EditeActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.v7.widget.RecyclerView 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread.access$800(ActivityThread.java:166) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.os.Handler.dispatchMessage(Handler.java:102) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.os.Looper.loop(Looper.java:136) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread.main(ActivityThread.java:5590) 09-23 11:55:53.288: E/AndroidRuntime(28333): at java.lang.reflect.Method.invokeNative(Native Method) 09-23 11:55:53.288: E/AndroidRuntime(28333): at java.lang.reflect.Method.invoke(Method.java:515) 09-23 11:55:53.288: E/AndroidRuntime(28333): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280) 09-23 11:55:53.288: E/AndroidRuntime(28333): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096) 09-23 11:55:53.288: E/AndroidRuntime(28333): at dalvik.system.NativeStart.main(Native Method) 09-23 11:55:53.288: E/AndroidRuntime(28333): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.v7.widget.RecyclerView 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.rInflate(LayoutInflater.java:762) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.inflate(LayoutInflater.java:499) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 09-23 11:55:53.288: E/AndroidRuntime(28333): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:331) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.Activity.setContentView(Activity.java:2018) 09-23 11:55:53.288: E/AndroidRuntime(28333): at ir.sheikhoo.sis.EditeActivity.onCreate(EditeActivity.java:13) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.Activity.performCreate(Activity.java:5447) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393) 09-23 11:55:53.288: E/AndroidRuntime(28333): ... 11 more 09-23 11:55:53.288: E/AndroidRuntime(28333): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.RecyclerView" on path: DexPathList[[zip file "/data/app/ir.sheikhoo.sis-22.apk"],nativeLibraryDirectories=[/data/app-lib/ir.sheikhoo.sis-22, /vendor/lib, /system/lib]] 09-23 11:55:53.288: E/AndroidRuntime(28333): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 09-23 11:55:53.288: E/AndroidRuntime(28333): at java.lang.ClassLoader.loadClass(ClassLoader.java:497) 09-23 11:55:53.288: E/AndroidRuntime(28333): at java.lang.ClassLoader.loadClass(ClassLoader.java:457) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.createView(LayoutInflater.java:566) 09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:703) 09-23 11:55:53.288: E/AndroidRuntime(28333): ... 21 more 并定位sdk android.support-23.2.1

enter image description here

这是我的sdk

enter image description here

1 个答案:

答案 0 :(得分:1)

我认为你的 cardview jar文件存在问题,它与其他库的版本不匹配。

第1,你需要使用 cardview 或其他低于 compileSdkVersion和targetSdkVersion 的库版本。在这种情况下,您使用版本 cardview-v7-21.0.0.jar ,因此 compileSdkVersion和targetSdkVersion 必须为21.0.0或更高。

第二,我认为您需要切换Android Studio,它可以轻松管理库。