The error is self-explanatory. Please have a careful look from
wherever you copied this piece of code. You main.xml file should have
a ListView with a specific id.

"@android:id/list" if your activity is extending the ListActivity.

Thanks and Regards,
Kumar Bibek

On May 5, 10:42 am, rcr <[email protected]> wrote:
> HI,
>
> I am new to android.
> i am getting with following problem
>
> " Your content must have a ListView whose id attribute is
> 'android.R.id.list' "
>
> I am sending my code.
> myList.java
> --------------------
> package com.example.Android;
>
> import android.app.Activity;
> import android.app.ListActivity;
> import android.content.Context;
> import android.os.Bundle;
> import android.view.LayoutInflater;
> import android.view.View;
> import android.view.ViewGroup;
> import android.widget.ArrayAdapter;
> import android.widget.ImageView;
> import android.widget.ListView;
> import android.widget.TextView;
>
> public class myList extends ListActivity {
>         TextView selection;
>         static final String[] items={"lorem", "ipsum", "dolor", "sit",
> "amet",
>         "consectetuer", "adipiscing", "elit", "morbi", "vel",
>         "ligula", "vitae", "arcu", "aliquet", "mollis",
>         "etiam", "vel", "erat", "placerat", "ante",
>         "porttitor", "sodales", "pellentesque", "augue",
>         "purus"};
>
>         public void onCreate(Bundle icicle) {
>                 super.onCreate(icicle);
>                 setContentView(R.layout.main);
>                 setListAdapter(new IconicAdapter());
>                 selection=(TextView)findViewById(R.id.label);
>                 }
>                 public void onListItemClick(ListView parent, View v,
>                 int position, long id) {
>                         selection.setText(items[position]);
>                 }
>                 class IconicAdapter extends ArrayAdapter {
>                 IconicAdapter() {
>                         super(myList.this, R.layout.row, items);
>                 }
>                 public View getView(int position, View convertView,
>                 ViewGroup parent) {
>                         LayoutInflater inflater=getLayoutInflater();
>                         View row=inflater.inflate(R.layout.row, parent, 
> false);
>                         TextView label=(TextView)row.findViewById(R.id.label);
>                         label.setText(items[position]);
>                         ImageView icon=(ImageView)row.findViewById(R.id.icon);
>                         if (items[position].length()>4) {
>                                 icon.setImageResource(R.drawable.ref);
>                         }
>                         else {
>                                 icon.setImageResource(R.drawable.ref);
>                         }
>                         return(row);
>                 }
>         }
>
> }
>
> ---------
> row.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="wrap_content"
> android:orientation="horizontal"
>
> <ImageView
> android:id="@+id/icon"
> android:layout_width="22px"
> android:paddingLeft="2px"
> android:paddingRight="2px"
> android:paddingTop="2px"
> android:layout_height="wrap_content"
> android:src="@drawable/ref"
> />
> <TextView
> android:id="@+id/label"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:textSize="44sp"
> />
> </LinearLayout>
>
> ----------------
> main.xml
>
> <?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:layout_width="fill_parent"
>     android:layout_height="wrap_content"
>     android:text="@string/hello"
>     />
> </LinearLayout>
>
> --
> 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 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
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