Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

I know that there has been simialr questions but I can't make it work even though I look at those. The error message is:

java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

. I have tried to change the id to list. In another. This what the code looks like:

 public class committeeFragment extends SherlockListFragment {

    private CommitteeAdapter adapter;

    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        adapter = new CommitteeAdapter(getActivity().getApplicationContext());
        setListAdapter(adapter);
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        return inflater.inflate(R.layout.fragment_committee, container, false);
    }

    public void
    refreshList() {
        adapter.updateDataSet();
        adapter.notifyDataSetChanged();
    }
}

It's using the following adapter:

    public class CommitteeAdapter extends BaseAdapter {
    private
    ArrayList<StudentCommittee> committeeList;
    private Context context;

    public CommitteeAdapter(Context context) {
        this.context = context;
        CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
        committeeList = dbAdapter.readAllCommittees();
    }

    public void updateDataSet() {
        CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
        committeeList = dbAdapter.readAllCommittees();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        StudentCommittee committee = committeeList.get(position);

        View v = vi.inflate(R.layout.list_item_committee, null);
        TextView sectionName = (TextView) v.findViewById(R.id.committee_namn);

        sectionName.setText(committee.getName());
        return v;
    }

    @Override
    public int getCount() {
        return committeeList.size();
    }

    @Override
    public StudentCommittee getItem(int position) {
        return committeeList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
}

Here is the xml-file that specifies the list(fragment_committee):

<?xml version="1.0" encoding="utf-8"?> <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
     android:tag="@string/tag_fragment_committee"
     android:background="@color/white" >

     <TextView
         style="@style/AppsolutText.Headline"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="Festerier" />

      <View
         android:layout_width="fill_parent"
         android:layout_height="2dp" 
         android:background="@drawable/divider_sliding_menu_item"/>

     <ListView
         android:id="@+id/list"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" />

     <TextView 
         style="@style/AppsolutText.Normal"
         android:id="@android:id/empty"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:text="Uppdatera för att se en lista över festerier och fadderier. Kräver internetanslutning."/>

 </LinearLayout>

Here is the xml for the list item:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="horizontal" >

     <ImageView
         android:id="@+id/committee_symbol"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="0"
         android:paddingBottom="10dp"
         android:paddingRight="10dp"
         android:paddingTop="10dp" />

     <TextView
         android:id="@+id/committee_namn"
         style="@style/AppsolutText.ListHeader"
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1" />

 </LinearLayout>

I hope that you can figure out what's wrong. I have another listview that has the same id (list) in another xml-file within the project. I don't know if that's a problem. Please help me solve the problem.

like image 786
Filip Eriksson Avatar asked Jul 28 '13 10:07

Filip Eriksson


1 Answers

The problem is here :

android:id="@+id/list"

you are adding a new id for your ListView but ListFragment needs a default Android ListView Id

change your ListView Id to :

<ListView
   android:id="@id/android:list"
   android:layout_width="match_parent"
   android:layout_height="wrap_content" />
like image 190
Arash GM Avatar answered Sep 28 '22 03:09

Arash GM