Your content MUST have a ListView whose id attribute is 'android.R.id.list'

조회수 1220회

우선 XML 파일의 내용은 이렇습니다.

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/list" >
</ListView>

소스코드

이건 액티비티 내용이구요.

public class ExampleActivity extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainlist);
    }
}

다른건 아무것도 안했습니다. 근데 아래와 같은 에러가 발생합니다.

Your content must have a ListView whose id attribute is 'android.R.id.list'

심지어 xml에 android:id="@+id/list" 이렇게 작성까지 했는데 말이죠. 도대체 뭐가 문제인걸까요?

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기

    ListView의 아이디를 아래처럼 수정해주세요.

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

    ListActivity를 쓰시면 xml에 리스트뷰 아이디를 무조건 android:id="@android:id/list"이렇게 지어야합니다.

    만약에 커스텀 리스트뷰를 만들고싶으시면 ListActivity를 상속받지마시고 그냥 Activity를 상속받으셔서 android 키워드 빼고 동일한 아이디를 주시면 됩니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)