2011-10-11 4 views
1

뷰 스텁에 문제가 있습니다. ViewStub NullPointerException

내 자바 파일

ViewStub stub = (ViewStub) findViewById(R.id.stub1); 
ArrayAdapter<String> content=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,files); 
View inflated=stub.inflate(); 
ListView people=(ListView)inflated.findViewById(R.id.friends); 
people.setAdapter(content); 

이 내가

다음과 뷰 스텁에서 팽창
<?xml version="1.0" encoding="utf-8"?> 
<merge xmlns:android="http://schemas.android.com/apk/res/android"> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id = "@+id/linear_details" > 
    <include layout="@layout/home_back_next_bar" /> 
    <ViewStub android:id="@+id/stub1" android:inflatedId="@+id/showlayout" 
android:layout="@layout/layout1" android:layout_width="fill_parent" 
android:layout_height="wrap_content"/> 

</LinearLayout> 
</merge> 

내 레이아웃 파일입니다으로 Viewstub를 초기화 XML입니다에 ViewStub입니다 :

 <?xml version="1.0" encoding="utf-8"?> 
    <ListView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/friends" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
/> 

이 코드는 listview의 인스턴스를 작성할 때 NullPointerException을 발생시킵니다. 그것. 모든 아이디어이 문제의 원인 및 해결 방법. 로그인 고양이에서 미리

오류를 많이

감사 : enter image description here

+0

로그에 널 포인터 예외를 표시하십시오. –

답변

1

대신

ListView people=(ListView)inflated.findViewById(R.id.friends); 

내가

ListView people=(ListView)stub.inflate(); 

를 사용하고는 아무 생각이 왜 일하지 사용 ?? . 워드 프로세서에 따르면 :하지만 그것은 didnt 한 일