Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, when I go to activity say unfortantly.... and close program
in my erro list say : Your content must have a ListView whose id attribute is 'android.R.id.list'
its my xml of activity :
XML
<?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" >

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

</LinearLayout>


and its my list_item activity :
XML
<?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" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        
       
        
        <ImageView
            android:id="@+id/img1"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:padding="5dp"
            android:layout_gravity="left" />
        
         <TextView
            android:id="@+id/txt1"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:textSize="15sp"
            android:text="Text_1" />
    </LinearLayout>

</LinearLayout>

and its my java cod :
Java
package com.momeni.shams;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;

public class Showperson extends ListActivity {

    public ListView list1;
    public String   number_of_keys;



    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_showperson);
        Bundle bundle = getIntent().getExtras();
        String catid = bundle.getString("catid");

        Dal db = new Dal(this);
        db.database();
        db.open();
        int count = db.count(catid);
        String[] name = new String[count];

        for (int i = 0; i < count; i++)
        {
            name[i] = db.Display(i, 3, catid);
        }
        setListAdapter(new MyAdapter(this, android.R.layout.simple_list_item_1, R.id.txt1, name));
        list1 = (ListView) findViewById(R.id.list);
        list1.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, final View view,
                                    int position, long id) {
                Intent i = new Intent(getApplicationContext(), Showdetale.class);
                number_of_keys = String.valueOf(position + 1);
                i.putExtra("key_number", number_of_keys);
                startActivity(i);
            }

        });
        //
        //        list1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, name));

    }

    private class MyAdapter extends ArrayAdapter<String> {

        public MyAdapter(Context context, int resource, int textViewResurceid, String[] strings) {
            super(context, resource, textViewResurceid, strings);

        }



        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater intflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View row = intflater.inflate(R.layout.list_item, parent, false);

            //            String stringName = String.valueOf(position + 1);
            //            int string_res_ID = getResources().getIdentifier(stringName, "string", getPackageName());
            //            String my_string = getResources().getString(string_res_ID);
            //            TextView tv = (TextView) row.findViewById(R.id.txt1);
            //            tv.setText(my_string);

            String imageName = "a" + String.valueOf(position + 1);
            int image_res_ID = getResources().getIdentifier(imageName, "drawable", getPackageName());
            ImageView iv = (ImageView) row.findViewById(R.id.img1);
            iv.setImageResource(image_res_ID);
            return row;

        }
    }

}



Pleazzzzz HELPPPP MEEEEEE :(
I search evry site but i cant solve this
Posted
Comments
Richard MacCutchan 18-Sep-14 3:57am    
Can you identify which line of code that the error occurs? What you have above looks OK, but it's difficult to guess where the exception happens.

1 solution

replace
HTML
<listview>
        android:id="@+id/list"...</listview>

to
HTML
<listview>
        android:id="@android:id/list"..</listview>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900