getViewByID Returns null for the Listview

I have got my main.xml as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <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>
</LinearLayout>

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;

     @SuppressWarnings("deprecation")
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main); // Set the content view.
            TextView txtView = (TextView)findViewById(R.id.textView1); // This works as expected
            mTweetsList = (ListView)findViewById(R.id.listView1); // This returns null

The line to get the list view returns null.

mTweetsList = (ListView)findViewById(R.id.listView1); -- 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?

Thanks

Answers


Have you tried cleaning the project (Eclipse->Project->Clean..)? I have found that sometimes R.java 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 asp.net-mvc less bundle multi-tenant

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