I am developing and android application that offers user registration and login. In the Navigation Drawer I put two TextViews for Login and Register. But, Where ever I put the OnClickListener for these TextViews it gives an error:
Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
please check this image, The TextViews are on the top of navigation drawer
Help. Thank You
Edited- Code
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
child=menu.findItem(R.id.action_cart).getActionView();
count_tv=(TextView)child.findViewById(R.id.cart_count_tv);
g=Globals.getInstance();
NavigationView navigationView=
(NavigationView)findViewById(R.id.nav_view);
View headerView=navigationView.getHeaderView(0);
TextView username=(TextView)findViewById(R.id.usernameNavBar);
TextView email=(TextView)findViewById(R.id.emailNavBar);
withLogin=(FrameLayout)findViewById(R.id.login_frame_layout);
wdoutLogin=(LinearLayout)findViewById(R.id.not_login_frame_layout);
if(g.loginstatus==true) {
withLogin.setVisibility(View.VISIBLE);
username.setText("name");
email.setText("email");
}else {
wdoutLogin.setVisibility(View.VISIBLE);
}
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(HomeActivity.this, "Login button pressed", Toast.LENGTH_SHORT).show();
}
});
}
