2017-05-16 6 views
-1

私は、OnCreateによってnav_headerにあるテキストビューを変更したいのですが、エラーが返されます。ヌルオブジェクトの参照nav_header_mainの接続方法は?

Picture 1 Picture 2

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference 
        at multimedia.slidemenu.MainActivity.onCreate(MainActivity.java:26) 
+0

をhttp://stackoverflow.com/questions/ 34973456 /どのように変更するとテキスト内のテキストのように見えるテキストのナビゲーションの引き出しのヘッダー このリンクをチェックしてみてください –

+3

[NullPointerExceptionとは何ですか? (http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) –

答えて

0

おかげMelicias、それはこのコードを使用して私の作品:

NavigationView navigationView= (NavigationView) findViewById (R.id.navigationView);  
View header = navigationView.getHeaderView(0); 

をそして私はこのようにテキストを設定することができます

TextView text = (TextView) header.findViewById(R.id.text); 
text.setText("xxxxx"); 
関連する問題