解决Android Listview addHeaderView setadapter的时候莫名NullPointerException
改代码的时候碰到的bug
Bug 1:
E/AndroidRuntime(15920): java.lang.RuntimeException: Unable to start activity ComponentInfo{ }: android.view.InflateException: Binary XML file line #35: Error inflating class fragment
解决思路
碰见 Binary XML file line #35
1 去检查了相关fragment xml配置 是否正确
2 检查 import 包 是否是 import android.app.v4.Fragment
Bug 2:
listview 莫名其妙 NullPointerException
E/AndroidRuntime(18769): Caused by: java.lang.NullPointerException
at android.widget.ListView.clearRecycledState
at android.widget.ListView.resetList
解决思路:
检查加载的header 或者 footer 的方式是否为 :
View header = getLayoutInflater().inflate(R.layout.header, null);
View footer = getLayoutInflater().inflate(R.layout.footer, null);
参考 :
//┏┓ ┏┓
//┏┛┻━━━┛┻┓
//┃ ┃
//┃ ━ ┃
//┃ ┳┛ ┗┳ ┃
//┃ ┃
//┃ ┻ ┃
//┃ ┃
//┗━┓ ┏━┛
// ┃ ┃ 神兽保佑
// ┃ ┃ 代码无BUG!
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
每日精进
原文:http://blog.csdn.net/aaawqqq/article/details/45953577