Android :ListView.setAdapter shows null exception
Hi I have a listview which bind data using setAdapter ,but when i try to bind it shows Null point exception
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();
}
}
in this this.post_Adapter.items.size() show count but ,i cant use l开发者_JAVA技巧istView1.setAdapter(new PostAdapter(this, R.layout.outkrys,listItems)); please Help ... Regards Augustine
If your Activity
is extending the ListActivity
class then ensure that your ListView
object must have the following attribute in your layout XML file:
android:id="@android:id/list"
See the documentation : http://developer.android.com/reference/android/app/ListActivity.html
精彩评论