[Solved] App crashes when accessing multiple textviews from navigation header


As it’s in the NavigationView

try navigationView.findViewById(viewId);

A strange thing I faced while I am using NavigationView is sometimes navigationView.findViewById(viewId) return null (reason may be we try to access (header) view before they are inflated to NavigationView)

Now I used to add manually header to NavigationView

    View header = LayoutInflater.from(this).inflate(R.layout.header_layout, null);
    navigationView.addHeaderView(header);

    TexView title = (TextView) header.findViewById(R.id.title);

solved App crashes when accessing multiple textviews from navigation header