Android - RecyclerView二进制XML文件行#2:无法解析索引6处的属性

时间:2015-12-30 21:28:15

标签: android xml

尝试编译RecyclerView时在Android Studio中出现以下错误

android.view.InflateException: Binary XML file line #2: Failed to resolve attribute at index 6: TypedValue{t=0x3/d=0x463 "res/drawable/ic_menu_moreoverflow_material.xml" a=1 r=0x10803d6}

堆栈跟踪:

12-30 21:01:43.067 32347-32347/com.uk.jacob.containerdroid E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.uk.jacob.containerdroid, PID: 32347
                                                                             android.view.InflateException: Binary XML file line #2: Failed to resolve attribute at index 6: TypedValue{t=0x3/d=0x463 "res/drawable/ic_menu_moreoverflow_material.xml" a=1 r=0x10803d6}
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                                 at com.uk.jacob.containerdroid.adapters.ContainerListRecyclerAdapter.onCreateViewHolder(ContainerListRecyclerAdapter.java:48)
                                                                                 at com.uk.jacob.containerdroid.adapters.ContainerListRecyclerAdapter.onCreateViewHolder(ContainerListRecyclerAdapter.java:18)
                                                                                 at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:4121)
                                                                                 at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3431)
                                                                                 at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3340)
                                                                                 at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1810)
                                                                                 at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1306)
                                                                                 at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1269)
                                                                                 at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:523)
                                                                                 at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:1988)
                                                                                 at android.support.v7.widget.RecyclerView.resumeRequestLayout(RecyclerView.java:1171)
                                                                                 at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:167)
                                                                                 at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                                                                                 at android.view.Choreographer.doCallbacks(Choreographer.java:670)
                                                                                 at android.view.Choreographer.doFrame(Choreographer.java:603)
                                                                                 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
                                                                                 at android.os.Handler.handleCallback(Handler.java:739)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                 at android.os.Looper.loop(Looper.java:148)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                              Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x3/d=0x463 "res/drawable/ic_menu_moreoverflow_material.xml" a=1 r=0x10803d6}
                                                                                 at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:705)
                                                                                 at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6890)
                                                                                 at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7071)
                                                                                 at android.support.v7.widget.RecyclerView$LayoutParams.<init>(RecyclerView.java:7018)
                                                                                 at android.support.v7.widget.RecyclerView$LayoutManager.generateLayoutParams(RecyclerView.java:4729)
                                                                                 at android.support.v7.widget.RecyclerView.generateLayoutParams(RecyclerView.java:2349)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:502)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                 at com.uk.jacob.containerdroid.adapters.ContainerListRecyclerAdapter.onCreateViewHolder(ContainerListRecyclerAdapter.java:48) 
                                                                                 at com.uk.jacob.containerdroid.adapters.ContainerListRecyclerAdapter.onCreateViewHolder(ContainerListRecyclerAdapter.java:18) 
                                                                                 at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:4121) 
                                                                                 at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3431) 
                                                                                 at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3340) 
                                                                                 at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1810) 
                                                                                 at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1306) 
                                                                                 at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1269) 
                                                                                 at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:523) 
                                                                                 at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:1988) 
                                                                                 at android.support.v7.widget.RecyclerView.resumeRequestLayout(RecyclerView.java:1171) 
                                                                                 at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:167) 
                                                                                 at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858) 
                                                                                 at android.view.Choreographer.doCallbacks(Choreographer.java:670) 
                                                                                 at android.view.Choreographer.doFrame(Choreographer.java:603) 
                                                                                 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) 
                                                                                 at android.os.Handler.handleCallback(Handler.java:739) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                 at android.os.Looper.loop(Looper.java:148) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

activity_main.xml中

<RelativeLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".activities.MainActivity">

<android.support.v7.widget.RecyclerView
    android:id="@+id/container_list_recycler"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"/>

container_list.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="?attr/listPreferredItemHeight"
    android:gravity="center_vertical"
    android:paddingLeft="8dp"
    android:paddingRight="8dp">

<TextView
    android:id="@+id/container_title"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_margin="8dp"/>

styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material">
    <!-- Customize your theme here. -->
</style>

ContainerListViewRecylerAdapter.java

package com.uk.jacob.containerdroid.adapters;


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.uk.jacob.containerdroid.R;
import com.uk.jacob.containerdroid.models.Container;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ContainerListRecyclerAdapter extends RecyclerView.Adapter<ContainerListRecyclerAdapter.ViewHolder> {
private List<Container> mData = new ArrayList<>();

public static class ViewHolder extends RecyclerView.ViewHolder {
    public TextView title;
    public TextView mTextView;

    public ViewHolder(View itemView) {
        super(itemView);
        title = (TextView) itemView.findViewById(R.id.container_title);
    }
}

public void updateList(List<Container> data) {
    mData = data;
    notifyDataSetChanged();
}

@Override
public int getItemCount() {
    return mData.size();
}

@Override
public ContainerListRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {
    View v = LayoutInflater.from(viewGroup.getContext())
            .inflate(R.layout.container_list, viewGroup, false);
    ViewHolder vh = new ViewHolder(v);
    return vh;
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    holder.title.setText(mData.get(position).getAliases());
}

public void addItem(int position, Container data) {
    mData.add(position, data);
    notifyItemInserted(position);
}

}

container_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="?attr/listPreferredItemHeight"
    android:gravity="center_vertical"
    android:paddingLeft="8dp"
    android:paddingRight="8dp">

    <TextView
        android:id="@+id/container_title"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_margin="8dp"/>

</LinearLayout>

的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.uk.jacob.containerdroid"
        minSdkVersion 23
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*'])
    compile 'com.android.support:appcompat-v7:23.+'
    compile 'com.fasterxml.jackson.core:jackson-core:2.4.2'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.4.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.6.4'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile "com.android.support:support-v4:+"
    compile "com.android.support:gridlayout-v7:+"
    compile "com.android.support:cardview-v7:+"
    compile 'com.android.support:recyclerview-v7:23.1.0'
}

1 个答案:

答案 0 :(得分:0)

您的代码文件ContainerListAdapter obBindViewHolder出错了,它错过了drawable xml文件中的属性ic drawable moreoverflow。不在您在此处发布的布局中。