android - Error inflating class Recycler View -
i beginner in android , trying learn recycler view using simple example.but getting exception seen in logcat.i have included necessary support libraries , added them build path of project. following files related recycler view:
logcat:
not find class android.support.v7.widget.recyclerview', referenced 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 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
<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
<?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
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
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[] = {1,2,3}; mlayoutmanager = new linearlayoutmanager(this); mrecyclerview.setlayoutmanager(mlayoutmanager); madapter = new adaptertest(a); mrecyclerview.setadapter(madapter); } }
can please help.
if using eclipse need folow steps
import app c:\productivity\android-sdks\extras\android\support\v7 . important "make sure have checked copy workspace option in import dialog box".
change sdk build version imported libraries android 6.0 project properties , proceed clean , build.
add recyclerview , appcompat in project build library shwon in pic below adding recycler view build path
done can develop material in eclipse.
Comments
Post a Comment