遇到此问题已经是ListView添加header时出现了问题。
创建Header的View时,用下面的方法
View header = View.inflate(this, R.layout.header_layout, null);
should fix it.
Edit: As mentioned in the comments, changing the ViewGroup Parameter of the inflate call also makes it work:
header = inflater.inflate(R.layout.header_layout, null, false);
避免Header View的父View有问题。
元问题及答案连接:
http://stackoverflow.com/questions/8275669/classcastexception-when-calling-listview-addheaderview