Now this line ListView list = (ListView)findViewById(R.id.list);
gives me error as R.id.list can not be resolved . My xml file is as

<?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"
  android:orientation="vertical"
  >

        <ListView android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
  <TextView
    android:id="@+id/footer"
    android:layout_width="fill_parent"
    android:layout_height="60dip"
    android:text="@string/footer"
    android:padding="4dip"
    android:background="#FF666666"
    />
</LinearLayout>

And java file as
public class AddRoom extends Activity
{
        private ListView lv1;
        String[] rooms ;
        String[] menuItems;
        public void onCreate(Bundle savedInstanceState)
        {
                System.out.println ("First stmt in onCreate of AddRoom");
                super.onCreate(savedInstanceState);
                try{
                setContentView(R.layout.addroom);}catch (Exception e)
{e.printStackTrace();}

                System.out.println ("After catch block");

                rooms = getResources().getStringArray(R.array.Room_array);
                // By using setAdpater method in listview we an add string 
array in
list.
                ListView list = (ListView)findViewById(R.id.list);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.listitem, rooms);
            list.setAdapter(adapter);
            registerForContextMenu(list);

        }
         //some other method
}


On Oct 16, 3:37 pm, "pramod.deore" <[email protected]> wrote:
> instead of extending ListActivity I had extend my class from Activity
> but still problem is not solved.
> On Oct 16, 2:44 pm, Kostya Vasilyev <[email protected]> wrote:
>
> >   Pramod,
>
> > Looks like you are using ListActivity, which expects that the list view
> > has a certain predefined ID.
>
> > That id is defined inside Android, and is the "android.R.id.list"
> > mentioned in the logcat.
>
> > Either change the layout to use"@id/android:list" (and also change the
> > parameter to findViewById), or change your activity to subclass from
> > Activity, not ListActivity.
>
> > I would recommend the latter, since your code doesn't really leverage
> > ListActivity.
>
> > -- Kostya
>
> > 16.10.2010 12:36, pramod.deore пишет:
>
> > > I am getting this error- Your content must have a ListView whose id
> > > attribute is 'android.R.id.list'
> > > my xml file is
>
> > > <?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"
> > >    android:orientation="vertical"
>
> > >    <ListView android:id="@+id/list"
> > >      android:layout_width="fill_parent"
> > >      android:layout_height="wrap_content"
> > >      />
> > >    <TextView
> > >      android:id="@+id/footer"
> > >      android:layout_width="fill_parent"
> > >      android:layout_height="60dip"
> > >      android:text="@string/footer"
> > >      android:padding="4dip"
> > >      android:background="#FF666666"
> > >      />
> > > </LinearLayout>
>
> > > and .java fiile is like
>
> > > public void onCreate(Bundle savedInstanceState)
> > >    {
> > >            System.out.println ("First stmt in onCreate of AddRoom");
> > >            super.onCreate(savedInstanceState);
> > >            setContentView(R.layout.addroom);
>
> > >            String[] rooms = 
> > > getResources().getStringArray(R.array.Room_array);
> > >            // By using setAdpater method in listview we an add string 
> > > array in
> > > list.
> > >            ListView list = (ListView)findViewById(R.id.list);
> > >        ArrayAdapter<String>  adapter = new ArrayAdapter<String>(this,
> > > R.layout.listitem, rooms);
> > >        list.setAdapter(adapter);
> > >        registerForContextMenu(list);
>
> > >    }
>
> > > and error is at line 19 which is- setContentView(R.layout.addroom);
> > > what is wrong?
>
> > --
> > Kostya Vasilyev -- WiFi Manager + pretty widget 
> > --http://kmansoft.wordpress.com
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to