Android:ListView.setAdapter显示null异常

时间:2011-02-02 07:57:29

标签: android

您好 我有一个listview使用setAdapter绑定数据,但是当我尝试绑定它时显示Null点异常

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
      try {
          listView1 = (ListView) findViewById(R.id.ListView);

        Thread t = new Thread() {
            public void run() {
                listItems=getList();
                pHandler.post(mUpdateResults);
            }
            };
        t.start();  
    } catch (Exception e) {

        progress.dismiss();

    }
}
final Handler pHandler = new Handler();

// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
    public void run() {
        updateTabData();
    }
};
private void updateTabData() {
    try {


        this.post_Adapter = new PostAdapter(this, R.layout.outkrys,
                listItems);

        Toast.makeText(OutKrys.this, "Inside updateTab after post_adapter intial "+this.post_Adapter.items.size(), Toast.LENGTH_LONG).show();
    listView1.setAdapter(new PostAdapter(this, R.layout.outkrys,listItems));                                
                progress.dismiss();
    } catch (Exception e) {
        Toast.makeText(OutKrys.this, "Inside updateTabData "+e, Toast.LENGTH_LONG).show();
        progress.dismiss();

    }
}

在这个this.post_Adapter.items.size()显示计数但是,我不能使用listView1.setAdapter(new PostAdapter(this,R.layout.outkrys,listItems)); 请帮忙 ... 关心奥古斯丁

1 个答案:

答案 0 :(得分:2)

如果您的Activity正在扩展ListActivity类,请确保您的ListView对象在布局XML文件中必须具有以下属性:

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

请参阅文档:http://developer.android.com/reference/android/app/ListActivity.html