Question

I am creating a Calculator. When calculations are made, I need them displayed, then clickable so I can delete individual figures. I followed this tutorial, and got this far. The only problem is when I run it, I get a FC and my logcat says this:

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

All of my research say to change my id to android.R.id.list. I tried this, but still getting the same error.

Here is my code:

CustomAdapter.java (extends ArrayAdapter)

private final Context context;
private final ArrayList<Calculations> items = null;
private final LayoutInflater inflater;
public CustomListAdapter(Context context, int textViewResourceId, ArrayList<Calculations>items){
    super(context, textViewResourceId, items);
    this.context = context;
    this.items = items;
    this.inflater = LayoutInflater.from(context);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final View v = convertView != null 
                       ? convertView
                       : infalter.inflate(R.layout.list_item, parent, false);

    final Calculations c = items.get(position);
    final TextView type = (TextView) v.findViewById(R.id.tvType);
    final TextView figure = (TextView) v.findViewById(R.id.tvFullFigure);
    final TextView amount = (TextView) v.findViewById(R.id.tvAmount);
    type.setText(c.getType());
    figure.setText(c.getFigure());
    amount.setText(c.getFigureAmount());

    return v;

}

acitivty_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="15dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:background="@drawable/concret_back"
    >

<!--Code remove for brevity-->

    <ListView
        android:id="@+id/android.R.id.list"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent" />

</RelativeLayout>

I have had this problem with another app I have done and never found a solution. So I though I would ask why do I keep getting the Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' error?

Thanks for any input.

Was it helpful?

Solution

Change your ListView id from

     <ListView
        android:id="@+id/android.R.id.list"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent" />

to

     <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top