当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Error when trying to launch new Activity android

问题描述:

I'm trying to launch an android activity from my Main activity, but I get force stop.

The logcaterror is like this:

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

But the activity that I try to launch already has a ListView with the id "list".

Any advice is appreciated.

UPDATE: Still can't figure out what's wrong.

Here's my code:

activity_all_apps.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin"

tools:context="com.example.app.AllAppsActivity">

<ListView

android:id="@android:id/list"

android:layout_width="fill_parent"

android:layout_height="wrap_content" />

</RelativeLayout>

and

AllAppsActivity.java

public class AllAppsActivity extends ListActivity

网友答案:

In your XML layout file related to this Activity you should have a ListView element that whose id is @android:id/list. Something like this.

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

</ListView>
分享给朋友:
您可能感兴趣的文章:
随机阅读: