2011-06-09 3 views
0

XML pertinente:Problème lors de la mise visibilité de LinearLayout

<LinearLayout 
    android:id="@+id/linear_layout_video_feed_list_view" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:layout_weight="2"> 
    <ListView 
    android:id="@+id/list_video_feed" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    </ListView> 
</LinearLayout> 

CODE pertinente:

linearLayoutVideoFeedListView = (LinearLayout) findViewById(R.id.linear_layout_video_feed_list_view); 
lv = (ListView) findViewById(R.id.list_video_feed) 

lv.setVisibility(GONE) œuvres mais linearLayoutVideoFeedListView.setVisibility(GONE) les causes NullPointer exception. Quelqu'un sait pourquoi?

+0

appelez-vous 'linearLayoutVideoFeedListView.setVisibility (GONE)' 'après lv = (ListView) findViewById (R.id.list_video_feed) '? –

+0

Pouvez-vous cacher une vue racine si c'est le parent le plus haut? – Spidy

+0

@Gabriel oui, je suis – yellavon

Répondre

1

Si linear_layout_video_feed_list_view n'a pas été aménagé avant d'appeler

linearLayoutVideoFeedListView.setVisibility (GONE)

il se traduira par un pointeur nul. Si tel est le problème ici, essayez le gonfler:

LayoutInflater gonfleur = (LayoutInflater) mContext.getSystemService (Context.LAYOUT_INFLATER_SERVICE); RelativeLayout myView = (RelativeLayout) mInflater.inflate (R.id.linear_layout_video_feed_list_view, null);

espoir qui aide

+0

Lors de la déclaration de mContext et mInflater: Contexte mContext; quel type est mInflater? – yellavon

+0

Et une autre pensée, le 'linearLayoutVideoFeedListView' doit être mis en place parce que je peux appeler' lv.setVisibility (GONE) 'qui est imbriqué à l'intérieur de' linearLayoutVideoFeedListView'. Droite? – yellavon

-2

Je voudrais essayer

linearLayoutVideoFeedListView.setVisibility(LinearLayout.GONE); 

des thats ce qui a toujours travaillé pour moi

+0

Je l'ai essayé et je reçois toujours l'exception NullPointerException. D'autres idées? Merci. – yellavon

Questions connexes