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

來源:互聯網
上載者:User
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;
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.