我正在为我的应用程序创建一个导航栏,然后我在这里遇到这个问题,有人可以告诉我在哪里修复它吗?我是新来的!! 我已经从布局到mainactivity设置了相同的ID,但是没有用
在空对象引用上'避免android.support.v4.widget.DrawerLayout.addDrawerListener(android.support.v4.widget.DrawerLayout $ DrawerListener)'
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//NavigationBar
drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this,drawerLayout,R.string.Open,R.string.Close);
actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final NavigationView navView = (NavigationView)findViewById(R.id.nav_view);
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override public boolean onNavigationItemSelected(@NonNull MenuItem item)
{
int id = item.getItemId();
if ( id == R.id.huongdan)
{
Toast.makeText(MainActivity.this,"Coming soon", Toast.LENGTH_SHORT).show();
}
else if ( id == R.id.banggia)
{
Toast.makeText(MainActivity.this,"Coming soon", Toast.LENGTH_SHORT).show();
}
else if ( id == R.id.thongtin)
{
Toast.makeText(MainActivity.this,"Coming soon", Toast.LENGTH_SHORT).show();
}
return true;
}
});