2012-04-07 3 views
0

필자는 목록보기에 헤더를 추가해야한다는 요구 사항이 있습니다. 다음은 "null 포인터 예외"를주는 listView.addHeaderView()

이 라인은

저를 해결하기 위해 무엇을 할 수 있는지 알려주세요 ", NullPointerException가"주는 나의 동일을 달성하기위한 코드 ..

 ListView listView; 
    listView = (ListView) findViewById(R.id.list_view); 
    //View header = View.inflate(this , R.layout.header, null); 
    LayoutInflater ll = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View v2 = ll.inflate(R.layout.header, null, false); 


    listView.addHeaderView(v2); 

그러나 "listView.addHeaderView (V2)"입니다 이 문제.

+0

당신이 스택 추적을 게시 할 수 있습니까? 어떤 것이 null, listView 또는 v2입니까? – Raffaele

답변

4

그냥이 시도 : 대신

listView.addHeaderView(LayoutInflater.from(this).inflate(R.layout.header, null)); 

을 :

LayoutInflater ll = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View v2 = ll.inflate(R.layout.header, null, false); 
listView.addHeaderView(v2); 
+0

이유를 설명해 주시겠습니까? – andresmafra