2013-07-15 4 views
5

나는 안드로이드 응용 프로그램을 개발해야합니다.안드로이드에 포함 된 레이아웃 숨기기

include 태그를 사용하여 다른 레이아웃 파일을 사용하는 레이아웃 파일을 만들었습니다.

<include 
    android:id="@+id/footer" 
    android:layout_width="match_parent" 
    android:layout_height="60dp" 
    android:layout_alignParentBottom="true" 
    layout="@layout/footer_tabs" /> 
    <include 
    android:id="@+id/footer1" 
    android:layout_width="match_parent" 
    android:layout_height="60dp" 
    android:layout_alignParentBottom="true" 
    layout="@layout/footertabs" /> 

응답이 null 일 때 포함 된 레이아웃을 표시하고 싶습니다. 그렇지 않으면 레이아웃을 숨기고 다른 것을 표시하고 싶습니다.

footertabs = (RelativeLayout) findViewById(R.id.footertab); 
footer_tabs = (RelativeLayout) findViewById(R.id.footer_tab); 

if (Constants.response==null) { 
    footertabs.setVisibility(View.VISIBLE); 
    footer_tabs.setVisibility(View.GONE); 
} 
else 
{ 
    footertabs.setVisibility(View.GONE); 
    footer_tabs.setVisibility(View.VISIBLE); 
} 

그러나 나는 다음과 같은 오류를 받고 있어요 : 여기에 지금까지 무엇을 가지고

07-15 17:19:09.893: E/AndroidRuntime(15143): Caused by: java.lang.NullPointerException 
07-15 17:19:09.893: E/AndroidRuntime(15143): at com.example.androidbestinuk.HomePage.onCreate(HomePage.java:56) 

이 오류를 디버깅 도와주세요.

답변

5

당신은 변경해야

footertabs = (RelativeLayout) findViewById(R.id.footertab); 
footer_tabs = (RelativeLayout) findViewById(R.id.footer_tab); 

footertabs = (RelativeLayout) findViewById(R.id.footer); 
footer_tabs = (RelativeLayout) findViewById(R.id.footer1); 
1

글쎄, 당신이 잘못된 이드를 사용하고있는 것처럼 보입니다. 어딘가에 널 포인터가 생겼어. (줄 번호가 없기 때문에 어디 있는지 모르겠다.)하지만 XML에있는 ID가 footer이고 footer1인데 코드에서 ID가 footertab 인 요소를 찾고있다. , 및 footer_tab. 이드의 성냥을 만들어야 해.

관련 문제