错误充气类回收站查看 [英] Error inflating class Recycler View

查看:128
本文介绍了错误充气类回收站查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的初学者,并试图利用这个简单的example.But作为Logcat.I看到已包括所有必要的支持库我得到异常学习回收站视图,并将它们添加到的构建路径项目。 以下是我的相关回收站视图文件:

I am a beginner in Android and trying to learn the Recycler View using this simple example.But I am getting the exception as seen in the Logcat.I have included all the necessary support libraries and added them to the build path of the project. Following are my files related to the recycler view:

logcat的:

 Could not find class android.support.v7.widget.RecyclerView', referenced   from method           com.example.rtest.MainActivity.onCreate
10-27 23:36:14.480: E/AndroidRuntime(12806): FATAL EXCEPTION: main
10-27 23:36:14.480: E/AndroidRuntime(12806): java.lang.RuntimeException:   Unable to start activity ComponentInfo    {com.example.rtest/com.example.rtest.MainActivity}:  android.view.InflateException: Binary XML file line #7: Error inflating class     android.support.v7.widget.RecyclerView

Activity_main.xml

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"
tools:context="${relativePackage}.${activityClass}" >

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

>
</android.support.v7.widget.RecyclerView>
</RelativeLayout>

my_text_view.xml

my_text_view.xml

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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text"
android:text="Hello List view!!!"        
/>
</LinearLayout>

AdapterTest.java

AdapterTest.java

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

public class AdapterTest extendsRecyclerView.Adapter<AdapterTest.ViewHolder>        {
private int[] mDataset;

public static class ViewHolder extends RecyclerView.ViewHolder {

public TextView mTextView;
public ViewHolder(View v) {
super(v);
mTextView = (TextView)v;
    }
}


public AdapterTest(int [] myDataset) {
mDataset = myDataset;
}


@Override
public AdapterTest.ViewHolder onCreateViewHolder(ViewGroup parent,int viewType) {

View v = LayoutInflater.from(parent.getContext()                           .inflate(R.layout.my_text_view, parent, false);

AdapterTest.ViewHolder vh = new AdapterTest.ViewHolder(v);
return vh;
}


@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.mTextView.setText(mDataset[position]);

}

@Override
public int getItemCount() {
return mDataset.length;
}
}

MainActivity.java

MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

public class MainActivity extends Activity {

private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mRecyclerView = (RecyclerView) findViewById(R.id.drawer);

int[] a = {1,2,3};

mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);

mAdapter = new AdapterTest(a);
mRecyclerView.setAdapter(mAdapter);
}
}

有人可以帮。

Can someone please help.

推荐答案

如果您使用的是Eclipse,你需要folow中这一步骤

If you are using eclipse you need to folow this steps

  1. 导入应用程序,一切从C:\产\ Android的软件开发工具包\演员\机器人\ SUPPORT \ V7。非常重要的请确保您在导入对话框中选中复制到工作区中选择

更改SDK构建版本为所有导入的库到Android 6.0,从项目属性,着手清理并生成。

Change SDK build version for all imported libraries to Android 6.0 from project properties , proceed with clean and build.

添加Recyclerview和appcompat在项目建设的图书馆,如下添加回收shwon在PIC以构建路径

Add Recyclerview and appcompat in your project build as library as shwon in pic below adding recycler view to build path

完成,现在你可以开发材料月食。

Done now you can develop for material in eclipse.

这篇关于错误充气类回收站查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆