RecycleView Android崩溃错误:资源ID#0x7f0d00aa类型#0x12无效

时间:2016-03-28 06:56:40

标签: java android xml android-recyclerview

我正在为android中的recycleview实现适配器,但它抛出错误资源ID#0x7f0d00aa类型#0x12无效。

这是 client_info_fragment_revision_layout.xml 的卡片布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardElevation="2dp"
        android:layout_margin="7dp"
        android:clickable="true"
        android:focusable="true">

    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" android:id="@+id/revMainLayout">

        <!--TOP-->
        <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" android:id="@+id/revRelativeTop">
            <ImageView android:id="@+id/imagePartRevision"
                       android:layout_width="28dp"
                       android:layout_height="28dp"
                       android:scaleType="fitXY"
                       android:layout_marginLeft="7dp" android:layout_marginTop="5dp"
                       android:src="@drawable/ic_indicator_program"/>
            <TextView
                    android:id="@+id/partRevision"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:maxLines="2"
                    android:padding="10dp"
                    android:text="Paper"
                    android:textSize="16sp" android:layout_marginLeft="34dp"/>
            <TextView
                    android:id="@+id/deadlineRevision"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:text="23-04-2016"
                    android:textSize="16sp"
                    android:padding="10dp"
                    android:layout_marginRight="7dp"/>

        </RelativeLayout>


        <!--MIDDLE-->
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" android:id="@+id/revLinearMiddle">
            <View
                    android:id="@+id/divider1"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#a4b9adba"/>
            <ListView
                    android:layout_width="wrap_content"
                    android:layout_height="120dp"
                    android:id="@+id/listViewRevision"/>
            <View
                    android:id="@+id/divider2"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#a4b9adba"/>
        </LinearLayout>

        <!--BOTTOM-->
        <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" android:id="@+id/revRelativeBottom">

            <TextView
                    android:id="@+id/statusRevision"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_toLeftOf="@+id/statusRevisionIndicator"
                    android:maxLines="2"
                    android:padding="10dp"
                    android:text="On Progress"
                    android:textSize="16sp"/>

            <ImageView
                    android:id="@+id/statusRevisionIndicator"
                    android:layout_width="28dp"
                    android:layout_height="28dp"
                    android:layout_alignBottom="@+id/statusRevision"
                    android:layout_alignParentRight="true"
                    android:layout_below="@id/divider"
                    android:layout_marginRight="7dp" android:layout_centerVertical="true"
                    android:layout_marginBottom="5dp" android:src="@drawable/ic_indicator_not_finished"/>
        </RelativeLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>

这是我的适配器的代码 RevisionRecycleCardsAdapter.java

package com.putraxor.prola.skripsi.client.activity.profileui;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.putraxor.prola.skripsi.R;
import com.putraxor.prola.skripsi.pojo.Revisi;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Putra on 27/03/2016.
 */
public class RevisionRecycleCardsAdapter extends RecyclerView.Adapter<RevisionRecycleCardsAdapter.CardViewHolder> {

    private ArrayList<Revisi> revision_list;
    Context context;
    public static class CardViewHolder extends RecyclerView.ViewHolder{
        ImageView imagePartRevision;
        ImageView statusRevisionIndicator;
        TextView partRevision;
        TextView deadlineRevision;
        TextView statusRevision;
        ListView listViewRevision;

        public CardViewHolder(View itemView) {
            super(itemView);
            imagePartRevision = (ImageView)itemView.findViewById(R.id.imagePartRevision);
            statusRevisionIndicator = (ImageView)itemView.findViewById(R.id.statusRevisionIndicator);
            partRevision = (TextView)itemView.findViewById(R.id.partRevision);
            deadlineRevision = (TextView)itemView.findViewById(R.id.deadlineRevision);
            statusRevision = (TextView)itemView.findViewById(R.id.statusRevision);
            listViewRevision = (ListView)itemView.findViewById(R.id.listViewRevision);
        }
    }

    public RevisionRecycleCardsAdapter(ArrayList<Revisi> revision) {
        this.revision_list = revision;
    }

    @Override
    public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        this.context = parent.getContext();
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.client_info_fragment_revision_layout, parent, false);
        CardViewHolder cardViewHolder = new CardViewHolder(view);
        return cardViewHolder;
    }

    @Override
    public void onBindViewHolder(final CardViewHolder holder, final int listPosition) {
        Revisi rev = revision_list.get(listPosition);
        int srcImagePartRevision = rev.getBagian().equalsIgnoreCase("Paper") ? R.drawable.ic_indicator_paper : R.drawable.ic_indicator_program;
        int srcStateIndicator = rev.isSelesai() ? R.drawable.ic_indicator_finished : R.drawable.ic_indicator_not_finished;
        String status = rev.isSelesai()?"Revisions Finished" : "On Process";
        holder.imagePartRevision.setImageResource(srcImagePartRevision);
        holder.partRevision.setText(rev.getBagian());
        holder.deadlineRevision.setText(rev.getDeadline());
        holder.statusRevision.setText(status);
        holder.statusRevisionIndicator.setImageResource(srcStateIndicator);
        String[] values = rev.getRevisi();
        ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < values.length; ++i) {
            list.add(values[i]);
        }
        StableArrayAdapter adapter = new StableArrayAdapter(this.context, R.id.listViewRevision, list);
        holder.listViewRevision.setAdapter(adapter);
    }

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

    private class StableArrayAdapter extends ArrayAdapter<String> {
        HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
        public StableArrayAdapter(Context context, int textViewResourceId, List<String> objects) {
            super(context, textViewResourceId, objects);
            for (int i = 0; i < objects.size(); ++i) {
                mIdMap.put(objects.get(i), i);
            }
        }

        @Override
        public long getItemId(int position) {
            String item = getItem(position);
            return mIdMap.get(item);
        }

        @Override
        public boolean hasStableIds() {
            return true;
        }
    }
}

2 个答案:

答案 0 :(得分:0)

中更改您的代码
  @Override
public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.R.layout.client_info_fragment_revision_layout, parent, false);
    CardViewHolder holder = new CardViewHolder (view);
}

答案 1 :(得分:0)

仅用于调试目的:

如果您使用的是Android工作室,请打开文件夹

下的 R.java
  

建设 - &GT; generated-&GT;源 - &GT; R-&GT;调试 - &GT; yourpackagename-&GT; R.java

然后在文件中搜索 0x7f0d00aa ;它就像

public static final int TextView01=0x7f0d00aa;

在资源文件夹下的xml文件中搜索相应的ID。然后检查XML内容语法,命名,源等。