I am trying to add list view in an array of Views. The null pointer exception is thrown at lv1.setAdapter. I don’t know why it’s happening.
Here is my code:
private ListView lv1;
private String lv_arr[]= new String[]{"Android","iPhone","BlackBerry","AndroidPeople"};
View[] vs = new View[1];
lv1=(ListView)findViewById(R.id.ListView01);
lv1.setAdapter(new ArrayAdapter<String> (MyCalendar.this,android.R.layout.simple_list_item_1,lv_arr));
vs[0] = lv1;
view.setListViewItems(vs);
here is the ListViewO1 inside list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/ListView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
are you setting your content view to list.xml?
Accept correct answers as correct and more people are likely to help you!
( it’s the greyed out tick on the left of a post (below the rating number), click it and it will go green to accept the answer ).