Android toolbars and whether they are nullable - android-layout

As seems to be typical for Android development, it doesn't work.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val toolbar: Toolbar = findViewById(R.id.toolbar)
//setSupportActionBar(toolbar) Why doesn't this work? Type mismatch: inferred type is android.widget.Toolbar but androidx.appcompat.widget.Toolbar? was expected
setSupportActionBar(findViewById(R.id.toolbar))
}
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
However:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rwb.toolbarhide, PID: 3989
java.lang.NoClassDefFoundError: android.widget.Toolbar
at com.rwb.toolbarhide.MainActivity.onCreate(MainActivity.kt:13)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Is this something to do with androidx and different Toolbars?
How can you tell if this is so?
What can be done to fix it?
What I wanted to know, however, was why the line commented out doesn't work.
How can we tell if findViewById is returning a Toolbar or a Toolbar? (in VisualStudio you would just hover the mouse, but not so in AndroidStudio -- it seems to be impossible).
So, if indeed we do have a Toolbar and not a Toolbar? then how can we pass it to setSupportActionBar?
(I want a Toolbar not a Toolbar? because it's a right nuisance having to ? and !! all over the place.)

import android.widget.Toolbar. It would have been done by the intellisense if it wasn't there as standard because I have no idea what I'm doing. Did it guess the wrong one?
This seems to have pacified it:
import androidx.appcompat.widget.Toolbar

Related

Background color of layout is not changing on clicking button with the help of radio button?

activity_main.xml;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_green_light"
android:backgroundTint="#color/material_dynamic_primary60"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".MainActivity"
tools:ignore="InvalidId">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/green"
android:textColor="#color/white"
android:textSize="20sp"
android:layout_marginTop="5dp"
android:id="#+id/green"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/red"
android:textColor="#color/white"
android:textSize="20sp"
android:layout_marginTop="5dp"
android:id="#+id/red"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/yellow"
android:textColor="#color/white"
android:textSize="20sp"
android:layout_marginTop="5dp"
android:id="#+id/yellow"/>
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/change_background"
android:textAllCaps="false"
android:backgroundTint="#android:color/holo_red_dark"
android:layout_marginTop="30dp"
android:textSize="20sp"
android:id="#+id/changeBackground"/>
</LinearLayout>
MainActivity.kt
package com.example.practiceapp
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.RadioButton
class MainActivity : AppCompatActivity() {
lateinit var green : RadioButton
lateinit var red : RadioButton
lateinit var yellow : RadioButton
lateinit var button: Button
lateinit var layout : LinearLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
green = findViewById(R.id.green)
red = findViewById(R.id.red)
yellow = findViewById(R.id.yellow)
layout = findViewById(R.id.linearLayout)
button = findViewById(R.id.changeBackground)
button.setOnClickListener{
if(green.isChecked){
layout.setBackgroundColor(Color.GREEN)
}
else if (red.isChecked){
layout.setBackgroundColor(Color.RED)
}else if(yellow.isChecked){
layout.setBackgroundColor(Color.YELLOW)
}
else{
layout.setBackgroundColor(Color.WHITE)
}
}
}
}
when I am printing a toast message, it gets printed. But the code for background color change is not working.
I have gone through line by line to find the error but not getting what is wrong there in the code. I am recently started learning android development, that is why unable to get the right output.
The IDE is not showing any error, either so that I can get what is wrong in the code.
Can anyone help?

Unresolved reference: fab, and inability to infer a type for parameter view

I seem to be stuck at the MainActivity.kt file and my app won't debug as it shows the mentioned errors.
This is for a music player app with a Navigation Drawer.
Edit : I have added the layout file after the comment as requested.
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
fab.setOnClickListener { view->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
val toggle = ActionBarDrawerToggle(
this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close)
drawer_layout.addDrawerListener(toggle)
toggle.syncState()
nav_view.setNavigationItemSelectedListener(this)
}
//as someone asked for the layout file as well here it is
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_gradient" />
<ImageView
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background="#drawable/echo_logo" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/navigation_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header"/>
</RelativeLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
There is no component called fab in your xml layout file. You still have the line of code that access a component called fab from your class. Remove
fab.setOnClickListener { view->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
It should get it to work.

How do I get a new TextView text to appear every time a button is clicked

I am new to this sorry. I am trying to create an Android Studio app that will have a different text appear for a question and answer TextView box field when a button is clicked. I was able to figure out how to get the text to change once, but how do I get it to cycle repeatedly every time the button is clicked?
Example Question and Answer I Want To Include for each time the button is clicked:
What is your Name?
My Name is Alyssa!
What is your age?
I am 28 years old.
What did you eat today?
I ate Spaghetti and Meatballs.
Here is my code:
MainActivity.kt
package example.alyssa.com.askalyssa
import android.app.Activity
import android.os.Bundle
import android.view.View
import android.widget.EditText
import android.widget.TextView
import kotlin.random.Random
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
fun buttonClick(v: View) {
val tv = findViewById(R.id.welcome) as TextView
tv.text = "Hi! I'm Alyssa"
val question = findViewById(R.id.questionfield) as TextView
question.text = "What is your name?"
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:text="Avatar Response Field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/welcome" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:text="Question Pop Up Field"
android:layout_width="wrap_content"
android:layout_height="37dp"
android:id="#+id/questionfield"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintHorizontal_bias="0.497"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/button"/>
<Button
android:text="Click to Ask Alyssa a Question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/textView2"
android:layout_marginBottom="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
android:onClick="buttonClick"/>
<ImageView
android:src="#drawable/ic_launcher_background"
android:layout_width="249dp"
android:layout_height="301dp"
android:id="#+id/imageView2"
app:layout_constraintTop_toBottomOf="#+id/welcome"
android:layout_marginTop="48dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/questionfield"/>
</android.support.constraint.ConstraintLayout>
i didn't understand your question completely but what i found is you are not listening the click of a button. So either implements the setonclickListner with MainActivity or you can directly use btn.setOnClickListner and perform the action on the textview accordingly.
If you still face any issue please comment here with proper query . i will surely help you.

Checkbox onClick xml method calling not working (Unresolved Method)

I have a map fragment inside a Drawer activity, I just added a checkbox to the mapFragment layout like so:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mapFragment">
<!-- TODO: Update blank fragment layout -->
<fragment
android:id="#+id/map1"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:tag="home"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context="com.tesseract.psiclops.zero.Main" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="87dp"
android:background="#drawable/edittext_designtst"
android:ems="10"
android:hint=" ■ ¿Qué buscas hoy?"
android:inputType="textPersonName"
android:textColor="#806b63"
android:textColorHint="#806b63"
android:textColorLink="#color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="#+id/follow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:checked="true"
android:onClick="followIO"
android:text="Sígueme"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
I have specified the onClick method "followIO" to trigger everytime the checkbox its checked/unchecked so the user can activate/deactivate camera updates of the map kind of like a "Follow me" checkbox.
I've declared the method inside the map fragment code since its the related activity(right?)
public class mapFragment extends Fragment implements OnMapReadyCallback, LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
.
.
.
public void followIO(View view){
boolean checked = ((CheckBox)view).isChecked();
if(checked){
//Updates on
}else{
//Updates off
}
}
}
but I still get the warning: "Cannot Resolve symbol followIO".
When I try to uncheck the checkbox the app crashes and throws this exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tesseract.psiclops.zerov2, PID: 5473
java.lang.IllegalStateException: Could not find method followIO(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatCheckBox with id 'follow'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:6256)
at android.widget.CompoundButton.performClick(CompoundButton.java:134)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
I'm still pretty new at android and I couldn't find other solution to my problem so I hope someone can help, Thank you in advance!
I just found out the answer, I'll post it here in case someone find it useful:
Apparently xml method declaration doesn't work well with fragments, the best aproach is to relate a variable to the checkbox and then call an onCLicklistener. Then I called the method from there like so:
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
.
.
.
CheckBox follow;
follow=view.findViewById(R.id.follow);
follow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
followIO(v);
}
});

java.lang.IllegalStateException: Required view not found even after setContentView()

I am facing a weird problem related to view not found but everything seems to be right with the code (at least to me). Infact the program was working fine till some time back. I am not sure what change that i made causing this issue. Could anyone of you point me the problem? Thank you.
The below is the exception trace:
FATAL EXCEPTION: main
Process: co.mycompany, PID: 3923
java.lang.RuntimeException: Unable to start activity ComponentInfo{co.mycompany/co.mycompany.activities.MainActivity}: java.lang.RuntimeException: Unable to bind views for co.mycompany.activities.MainActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5065)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to bind views for co.mycompany.activities.MainActivity
at butterknife.ButterKnife.bind(ButterKnife.java:322)
at butterknife.ButterKnife.bind(ButterKnife.java:237)
at co.mycompany.activities.MainActivity.onCreate(MainActivity.java:51)
at android.app.Activity.performCreate(Activity.java:5249)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2165)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250) 
at android.app.ActivityThread.access$800(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5065) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.IllegalStateException: Required view 'thUserProfilePic' with ID 2131558656 for field 'mUserProfilePic' was not found. If this view is optional add '#Nullable' annotation.
at butterknife.ButterKnife$Finder.findRequiredView(ButterKnife.java:140)
at co.mycompany.activities.MainActivity$$ViewBinder.bind(MainActivity$$ViewBinder.java:17)
at co.mycompany.activities.MainActivity$$ViewBinder.bind(MainActivity$$ViewBinder.java:8)
at butterknife.ButterKnife.bind(ButterKnife.java:319)
at butterknife.ButterKnife.bind(ButterKnife.java:237) 
at co.mycompany.activities.MainActivity.onCreate(MainActivity.java:51) 
at android.app.Activity.performCreate(Activity.java:5249) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2165) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250) 
at android.app.ActivityThread.access$800(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5065) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
at dalvik.system.NativeStart.main(Native Method) 
MainActivity.class
#Bind(R.id.thUserProfilePic)
CircleImageView mUserProfilePic;
#Bind(R.id.thUserDisplayName)
TextView mUserDisplayName;
#Bind(R.id.editProfileLink)
ImageView editProfileLink;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(mToolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawerLayout.setDrawerListener(toggle);
toggle.syncState();
mNavigationView.setNavigationItemSelectedListener(this);
navigate(AppScreen.HOME);
}
R.layout.activity_main
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:id="#+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" tools:openDrawer="start">
<include layout="#layout/app_bar_main" android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView android:id="#+id/nav_view"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_gravity="start" android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main" app:menu="#menu/activity_main_drawer"
android:background="#color/white"/>
</android.support.v4.widget.DrawerLayout>
R.layout.nav_header_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="#dimen/nav_header_height"
android:background="#drawable/side_nav_bar"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:theme="#style/ThemeOverlay.AppCompat.Dark" android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="#+id/editProfileLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_edit_white_24dp"
android:layout_gravity="end|right"/>
<include layout="#layout/user_thumbnail_large"/>
</LinearLayout>
R.layout.user_thumnail_large
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:id="#+id/userThumbnailLargeContainer">
<de.hdodenhof.circleimageview.CircleImageView android:layout_width="75dp" android:layout_height="75dp"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:src="#drawable/ic_face_white_48dp" android:id="#+id/thUserProfilePic" />
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing" android:text="John"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:id="#+id/thUserDisplayName"
android:textColor="#color/textColorSecondary"/>
</LinearLayout>
I am into second day of research and could not able to figure out what the issue is.
The issue is with support Library version. I was getting the above error since i upgraded support library to 23 version.
The below link has the solution.
NavigationView get/find header layout

Resources