android - ViewStub NullPointerException -
i have problem view stub.
this viewstub in java file
viewstub stub = (viewstub) findviewbyid(r.id.stub1); arrayadapter<string> content=new arrayadapter<string>(this,android.r.layout.simple_list_item_1,files); view inflated=stub.inflate(); listview people=(listview)inflated.findviewbyid(r.id.friends); people.setadapter(content);
this xml initialize viewstub
<?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android"> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id = "@+id/linear_details" > <include layout="@layout/home_back_next_bar" /> <viewstub android:id="@+id/stub1" android:inflatedid="@+id/showlayout" android:layout="@layout/layout1" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </linearlayout> </merge>
my layout file inflated in view stub follows:
<?xml version="1.0" encoding="utf-8"?> <listview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/friends" android:layout_width="fill_parent" android:layout_height="wrap_content" />
this code gives me nullpointerexception when creating instance of listview fill it. ideas causes problem , how solve.
thanks alot in advance
error in log cat:
the reason didnt work: according docs : http://developer.android.com/reference/android/view/viewstub.html#inflate()
you doing findviewbyid on "the inflated layout resource" listview looking for. .
Comments
Post a Comment