getViewByID Returns null for the Listview

I have got my main.xml as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <ListView android:layout_height="wrap_content" android:id="@+id/listView1" android:layout_width="match_parent"></ListView>

Now i want to get the ListView with id listView1 in the onCreate event of the activity. Here goes my code to achieve this stuff ..

public class TwitterClient extends Activity {
    private static ListView mTweetsList;

        public void onCreate(Bundle savedInstanceState) {
            setContentView(R.layout.main); // Set the content view.
            TextView txtView = (TextView)findViewById(; // This works as expected
            mTweetsList = (ListView)findViewById(; // This returns null

The line to get the list view returns null.

mTweetsList = (ListView)findViewById(; -- Does not work and returns null !!

where as when i use the same function to find the textview by id in the same layout, it works all fine. Can anyone point me to what might be an error here?



Have you tried cleaning the project (Eclipse->Project->Clean..)? I have found that sometimes gets messed up.

Check what target have you taken, is it Android 2.2 ? It is working fine in Android2.2 . If the error continues clean & build the project and restart the eclipse.

Need Your Help

Using archiver to zip batch of folders

javascript zip

I am trying to zip batch of folders , so I am using archiver

Bundling multiple css files for a multi tenant site?

css less bundle multi-tenant

Our mvc application currently has a single style for all our tenants.