1. 程式人生 > >使用ListView的addFooterView或者addHeaderView報錯或者不知名的異常:at android.widget.ListView.clearRecycledState(List

使用ListView的addFooterView或者addHeaderView報錯或者不知名的異常:at android.widget.ListView.clearRecycledState(List

Caused by: java.lang.NullPointerException
    at android.widget.ListView.clearRecycledState(ListView.java:522)
    at android.widget.ListView.resetList(ListView.java:508)
    at android.widget.ListView.setAdapter(ListView.java:440)
    at com.company.myapp.MyActivity.refreshList(MyActivity.java:85)
    at com.company.myapp.MyActivity.onCreate(MyActivity.java:37)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    ... 11 mored
當發生這種狀況。。。。,eclipse得到的異常就在你listView.setAdapter(adapter);這句話中。。。你怎麼看listView和adapter都沒有空值,正納悶時
你應該要考慮一下被你新增的FooterView或者HeaderView是否為null,因為空的話。。。ListView就無法測量高度。。。然後無法佈局。。最後就報錯了。。。還有addFooterView和addHeaderView這兩個方法一定要放在
listView.setAdapter(adapter);前面,要不然死活都不會出現你想要的FooterView或者HeaderView;