ListView.addHeaderView抛出的异常及解决方法

   错误代码:  
   LVbook=(ListView)findViewById(R.id.booklistID);
    try { LVbook.addHeaderView(getLayoutInflater().inflate(R.id.booklist_headid, null)); } catch (Exception e) { e.printStackTrace(); }
  正确代码:
     try {
              LVbook.addHeaderView(getLayoutInflater().inflate(R.layout.booklist_head, null));
        } catch (Exception e) {
             e.printStackTrace();
        }
相关API信息:
public View inflate(int resource, ViewGroup root)

Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.

Parameters:
resource - ID for an XML layout resource to load (e.g., R.layout.main_page)------>问题出现在这里,这里需要的是一个Layout布局ID号,
                                             上面写的是View ID号,犯了个低级错误
root - Optional view to be the parent of the generated hierarchy.

Returns:
The root View of the inflated hierarchy. If root was supplied, this is the root View; otherwise it is the root of the
inflated XML file.
错误截图:

posted @ 2014-06-22 11:37  lyyh.victory  阅读(294)  评论(0编辑  收藏  举报