RunTimeException android

时间:2012-06-11 06:49:45

标签: android android-listview runtimeexception

我的Android应用程序从logcat给我这个错误:

  

引起:java.lang.RunTimeException:您的内容必须有   ListView的id属性为'android.R.id.list'

这是我的代码:

package com.WNF;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.app.ListActivity;
import android.content.Intent;


public class Actiemenu extends ListActivity{

@Override 
public void onCreate(Bundle savedInstanceState) { 

super.onCreate(savedInstanceState); 
setContentView (R.layout.actiemenu);

final String[] array = new String[] {
        "Ding", "AnderDing", "Nogeending", "laatseding"
    };

setListAdapter(new ArrayAdapter<String> (this, R.layout.actiemenu, array));
    ListView lv = getListView();
    lv.setTextFilterEnabled(true);



lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

        if (position == 0) {
            Intent een = new Intent(v.getContext(), Acties.class);
            startActivity(een);
        }
        else if (position == 1) {
            Intent twee = new Intent(v.getContext(), Acties2.class);
            startActivity(twee);
        }
    }
});
getIntent();
}
}

任何想法可能是什么问题??

2 个答案:

答案 0 :(得分:2)

ListView放入ID为

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

答案 1 :(得分:0)

导入此

import your.package.name.R

在你的情况下:

import com.WNF.R

导入时会出现此问题

android.R

而不是

package.name.R;