c# - Null reference error while inflating a textview -


i'm adding textview header listview, in xamarin android app. following instructions in ericosg's answer this question, put textview in separate axml file, , tried add header list view.

running app gets following error @ line activity tries inflate textview:

[monodroid] unhandled exception: [monodroid] android.content.res.resources+notfoundexception: exception of type 'android.content.res.resources+notfoundexception' thrown. . . . [monodroid]   --- end of managed exception stack trace --- [monodroid] android.content.res.resources$notfoundexception: resource id #0x7f050006 type #0x12 not valid [monodroid]     @ android.content.res.resources.loadxmlresourceparser(resources.java:2250)   etc. 

here code:

in activity .cs file:

mylistview = findviewbyid<listview>(myapp.resource.id.mylist);          android.views.view myheader =              this.layoutinflater.inflate(myapp.resource.id.questiontext, mylistview);          mylistview.addheaderview(myheader); 

listview definition:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent">     <listview         android:id="@+id/mylist"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_weight="1" />     </relativelayout> 

header definition:

<?xml version="1.0" encoding="utf-8"?>         <textview xmlns:android="http://schemas.android.com/apk/res/android"             android:id="@+id/questiontext"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:drawabletop="@+id/myimage" /> 

a few things:

you attempting inflate id resource instead of layout:

 android.views.view myheader = this.layoutinflater.inflate(myapp.resource.id.questiontext, mylistview); 

the inflate call layoutinflater accepts resource.layout elements. change to:

android.views.view myheader = this.layoutinflater.inflate(resource.layout.header, mylistview); 

secondly, in header.xml layout file, textview android:drawabletop not accept id references throw inflateexception when layoutinflator attempts build layout.

from docs:

android:drawabletop

the drawable drawn above text.

may reference resource, in form "@[+][package:]type:name" or theme attribute in form "?[package:][type:]name".

may color value, in form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

change either reference valid color or drawable (@drawable/myimage) or inline color declartion (#fff).

lastly, can't add child views or header views listview without using adapter:

consider re-reading xamarin docs listviews , adapters better understand subject.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -