Question Detail

How to resolve Error with onClick in NavigationView headerLayout Android
I have already try call clickevent with id but the same problem.

E/AndroidRuntime: FATAL EXCEPTION: main
   Process: com.vbagetech.taxmunshi.gstbillingapp, PID: 14363
                   java.lang.IllegalStateException: Could not find method editprofile(View) in a parent or ancestor Context for android:onClick attribute defined on view class with id 'edit_profile_ID'
 at android.view.View.performClick(
 at android.view.View$
 at android.os.Handler.handleCallback(
 at android.os.Handler.dispatchMessage(
 at android.os.Looper.loop(
 at java.lang.reflect.Method.invokeNative(Native Method)
 at java.lang.reflect.Method.invoke(
 at dalvik.system.NativeStart.main(Native Method)


Thread Reply


- 3 years ago

You can't use them Views without Inflating Main View use below code for this. It is working fine for me.

View headerView = navigationView.inflateHeaderView(R.layout.nav_header_dashboard);
  ImageButton edit_profile=(ImageButton)headerView.findViewById(;
  edit_profile.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
          startActivity(new Intent(getBaseContext(),EditProfileActivity.class));