2013-07-15 13 views
5

Devo sviluppare un'applicazione Android.Nascondere il layout incluso in Android

Ho creato un file di layout che utilizza un altro file di layout utilizzando il tag 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" /> 

Mi piacerebbe mostrare il layout incluso quando una risposta è nullo, altrimenti vorrei nascondere il layout e mostrare l'altro. Ecco quello che ho finora:

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); 
} 

Ma sto ottenendo il seguente errore:

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) 

Please help me eseguire il debug di questo errore.

risposta

5

si dovrebbe cambiare

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

con

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

Bene, mi sembra che tu stia usando l'ID sbagliato. Stai ottenendo un puntatore nullo da qualche parte (non sono sicuro dove perché non ci sono numeri di riga), ma vedo nel tuo xml che hai id, footer e footer1, ma nel tuo codice stai cercando di trovare elementi con ID footertab e footer_tab. Dovresti fare la partita di questo id.

Problemi correlati