android - Why is this ListView null? -


i'm completing part of google android tutorial (this part precise) , i've hit snag. i'm trying set adapter of listview custom arrayadapter. unfortunately, findviewbyid seems returning null (which means can't set adapter).

here's relevant code:

mainactivityfragment

private final string log_tag = mainactivityfragment.class.getsimplename(); private artistitemadapter artistsadapter;  public mainactivityfragment() { }  @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     view rootview = inflater.inflate(r.layout.fragment_main, container, false);     artistsadapter = new artistitemadapter(getactivity(), r.layout.list_item_artist, new pager<artist>().items);      listview artistslist = (listview) rootview.findviewbyid(r.id.listviewartists);     artistslist.setadapter(artistsadapter);     return rootview; }  @override public void onstart() {     edittext searchbar = (edittext) getview().findviewbyid(r.id.searchedittext);      searchbar.setoneditoractionlistener(new textview.oneditoractionlistener() {         artistspager artists;          @override         public boolean oneditoraction(textview v, int actionid, keyevent event) {             boolean handled = false;             if (actionid == editorinfo.ime_action_search) {                 fetchartiststask artiststaskcall = new fetchartiststask();                 artiststaskcall.execute(string.valueof(v.gettext()));                 handled = true;             }             return handled;         }     }); } 

mainactivity.oncreate()

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main); } 

fragment_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=".mainactivityfragment">  <edittext     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/searchedittext"     android:inputtype="textfilter"     android:imeoptions="actionsearch"     android:drawableleft="@android:drawable/ic_menu_search"     android:hint="search artist"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:layout_alignparentright="true"     android:layout_alignparentend="true" />  <listview     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:id="@+id/listviewartists"     android:layout_below="@+id/searchedittext"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true" /> </relativelayout> 

activity_main.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/fragment" android:name="com.example.android.spotifyproject.mainactivityfragment" tools:layout="@layout/fragment_main" android:layout_width="match_parent" android:layout_height="match_parent" /> 

logcat: http://pastebin.com/cunf05af

it's not listview null, it's data sent adapter when created it, when try set adapter on listview calls list.size() on data(null), , that's error is.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -