Help with a ListActivity, activity crashes


Last Updated:

  1. Mattimus

    Mattimus New Member This Topic's Starter

    Joined:
    Jul 27, 2010
    Messages:
    3
    Likes Received:
    0
    Hi guys, if someone could give me a hand that would be great -

    The program crashes when this activity is initiated and i'm not sure why. When all the functions are gone except the

    public class DetailForm extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.detail_form);
    }
    }

    the activity gets a force close. when i change the EXTENDS command from LISTActivity to => Activity it will load... but not as a ListActivity

    any thoughts?
     

    Advertisement
  2. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    Does your detail_form.xml layout file contain a ListView?
     
  3. Mattimus

    Mattimus New Member This Topic's Starter

    Joined:
    Jul 27, 2010
    Messages:
    3
    Likes Received:
    0
    yes, the XML file detail_form.xml is as follows:


    <?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:background="@drawable/blankbakgrnd"
    >


    <ListView
    android:id="@+id/subjects"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"

    />


    </LinearLayout>
     
  4. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    You need to set the adapter for your listview before you call setcontentview.
     
  5. Mattimus

    Mattimus New Member This Topic's Starter

    Joined:
    Jul 27, 2010
    Messages:
    3
    Likes Received:
    0
    okay, i will try that, thanks
     
  6. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    I think that if you have an empty option in the xml then you won't need to set the adapter first.
     
  7. Neelesh5

    Neelesh5 New Member

    Joined:
    Feb 23, 2012
    Messages:
    1
    Likes Received:
    0
    Guys!! I am stuck with the same problem...I have to use ListView in my project. If I use only list view without setting the content view, it works. But I have to use but simultaneously


    public class StudentActivity extends ListActivity
    {


    String[] name = {"pen", "Lighter", "Chair"};

    EditText txtList,txtName;
    int i=0;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(StudentActivity.this, android.R.layout.simple_expandable_list_item_1,name));
    setContentView(R.layout.main);
    txtName = (EditText) findViewById(R.id.txtName);

    }


    }


    Please Suggest Something...
     
  8. miXer

    miXer Well-Known Member

    Joined:
    Aug 12, 2010
    Messages:
    313
    Likes Received:
    51
    I think the reason for your crash is that when you extend your activity to ListActivity, then your ListView in the xml file needs to have a special Android id for the ListActivity to recognize it:
    Code (Text):
    1. android:id="@+id/android:list"
     

Share This Page

Loading...