简体   繁体   English

蚂蚁,错误膨胀类android.support.v7.widget.RecyclerView

[英]Ant, Error inflating class android.support.v7.widget.RecyclerView

Let's create a clean new project: 让我们创建一个干净的新项目:

$ mkdir ApiTest
$ android create project --target android-22 --name ApiTest \
 --path ./ApiTest --activity MyActivity --package com.example.apitest

Only add RecyclerView to layout so res/layout/main.xml looks: 仅将RecyclerView添加到布局中,这样res/layout/main.xml看起来如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/recycler_view"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

Copy support libraries from ${ANDROID_SDK_PATH}/extras/android/support/v7/ : ${ANDROID_SDK_PATH}/extras/android/support/v7/复制支持库:

$ ls ApiTest/libs/
android-support-v4.jar            android-support-v7-cardview.jar
android-support-v7-appcompat.jar  android-support-v7-recyclerview.jar

Build & install: 构建并安装:

$ ant debug
$ adb install -r bin/ApiTest-debug.apk

And when I open the Activity exception is raised: 当我打开Activity异常时:

09-28 20:02:02.346: E/AndroidRuntime(28688): FATAL EXCEPTION: main
09-28 20:02:02.346: E/AndroidRuntime(28688): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.apitest/com.example.apitest.MyActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
09-28 20:02:02.346: E/AndroidRuntime(28688):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2357)
09-28 20:02:02.346: E/AndroidRuntime(28688):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2419)
...

What is wrong here? 怎么了

I compile on 64bit Fedora 21 using openjdk java compiler: 我使用openjdk java编译器在64位Fedora 21上进行编译:

$ java -version
openjdk version "1.8.0_60"
OpenJDK Runtime Environment (build 1.8.0_60-b27)
OpenJDK 64-Bit Server VM (build 25.60-b23, mixed mode)

I overlooked that there are two types of Android Support Libraries. 我忽略了两种类型的Android支持库。 Libraries without resources (eg android-support-v4 ) and libraries with resources (eg appcompat and recyclerview ). 没有资源的库(例如android-support-v4 )和有资源的库(例如appcompatrecyclerview )。 See Adding Support Libraries . 请参阅添加支持库

To add recyclerview library (with resources) using command line and ant build tool first copy whole recyclerview directory from Android SDK directory to your project directory and update ant build files 要使用命令行和ant生成工具添加recyclerview库(包含资源),请先将整个recyclerview目录从Android SDK目录复制到您的项目目录中,然后更新ant生成文件

$ cd ${ANDROID_PROJECT_DIR}
$ cp -r ${ANDROID_SDK_DIR}/extras/android/support/v7/recyclerview/ .
$ android update lib-project --path recyclerview --target android-22
$ android update project --path . -l recyclerview

The third command should add line android.library=true to recyclerview/project.properties which in my case didn't so I added it manually. 第三个命令应将android.library=true行添加到recyclerview/project.properties ,在我的情况下没有,因此我手动添加了它。 When I tried it with appcompat library it work as expected. 当我尝试使用appcompat库时,它可以按预期工作。

Another thing is that in the recyclerview/src directory was missing. 另一件事是,缺少recyclerview/src目录。 So simply create 所以只需创建

$ mkdir recyclerview/src

And that is it. 就是这样。 Now it compiles and runs. 现在,它可以编译并运行。

$ ant clean && ant debug && adb install -r bin/ApiTest-debug.apk

These links helped me: 这些链接帮助我:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误膨胀类 android.support.v7.widget.RecyclerView - Error inflating class android.support.v7.widget.RecyclerView 错误膨胀类 android.support.v7.widget.RecyclerView(Eclipse) - Error inflating class android.support.v7.widget.RecyclerView(Eclipse) 收到错误“android.view.InflateException:膨胀 class android.support.v7.widget.RecyclerView 时出错” - recieving error “android.view.InflateException: Error inflating class android.support.v7.widget.RecyclerView” 将.aar内的类android.support.v7.widget.RecyclerView膨胀时出错 - Error inflating class android.support.v7.widget.RecyclerView inside an .aar 启动活动时错误膨胀类 android.support.v7.widget.RecyclerView - Error inflating class android.support.v7.widget.RecyclerView when starting activity 无法解决错误膨胀类android.support.v7.widget.RecyclerView - Not able to resolve Error inflating class android.support.v7.widget.RecyclerView 没有找到类“android.support.v7.widget.RecyclerView - Didn't find class "android.support.v7.widget.RecyclerView android.support.v7.widget.RecyclerView$ViewHolder 的 class 文件 - class file for android.support.v7.widget.RecyclerView$ViewHolder eclipse中无法启动android.support.v7.widget.Recyclerview错误 - android.support.v7.widget.Recyclerview could not be initiated error in eclipse RecyclerView没有LayoutManager android.support.v7.widget.RecyclerView - RecyclerView has no LayoutManager android.support.v7.widget.RecyclerView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM