I have an activity, which is a NavigationDrawer
Activity and am having another activity extend this activity. When I start this child activity, I get the famous java.lang.NullPointerException
Caused by: java.lang.NullPointerException
at com.testapp.ShopActivity.onCreate(ShopActivity.java:23)
I don't see why this is happening since I have done everything the right way in my onCreate()
method.My full ShopActivity class code:
public class ShopActivity extends BaseDrawerActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button navButton = (Button)findViewById(R.id.nav);
navButton.setOnClickListener(new View.OnClickListener() { //<-Line 23
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), BaseDrawerActivity.class);
startActivity(intent);
}
});
}
@Override
public int getLayoutResourceId() {
return R.layout.activity_shop;
}
}
Not sure why this is happening.Without the button, ShopActivity
works fine and has a navigation drawer, same as the one in BaseDrawerActivity
. I have tried implementing OnClickListener
but I get the same error
EDIT
This is the content of the oncreate()
method of the BaseDrawerActivity
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base_drawer);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
if I change setContentView(R.layout.activity_base_drawer);
I start getting the same error on navigationDrawerFragment