I'm trying to implement a navigation bar within my android application. However, my compilers complains with following errors:
Error:(39, 25) error: cannot find symbol variable drawer_open
Error:(39, 47) error: cannot find symbol variable drawer_close
My code:
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends ActionBarActivity {
/***********************************************************
MEMBERS
**********************************************************/
private Toolbar m_toolbar;
private String m_navTitles[] = {"Nr. 1", "Nr. 2", "Nr. 3", "Nr. 4" };
private int m_icons[] = {R.drawable.ic_action, R.drawable.ic_action, R.drawable.ic_action, R.drawable.ic_action};
private DrawerLayout m_drawer;
private ActionBarDrawerToggle m_drawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* Set toolbar */
m_toolbar = (Toolbar) findViewById(R.id.tool_bar); //find toolbar from layout
setSupportActionBar(m_toolbar); //call to set toolbar as the ActionBar
/* Set navigation drawer */
m_drawer = (DrawerLayout) findViewById(R.id.DrawerLayout); //assign drawer object to view
m_drawerToggle = new ActionBarDrawerToggle(this, m_drawer, m_toolbar, R.string.drawer_open, R.string.drawer_close){
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
// code here will execute once the drawer is opened
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
// Code here will execute once drawer is closed
}
}; // made drawer toggle object
m_drawer.setDrawerListener(m_drawerToggle);
m_drawerToggle.syncState();
}
Please note that my code for the navigation drawer is not finished yet. I wanted to fix the drawer_open/drawer_close errors first.
Many thanks in advance!
Did you have
drawer_open
anddrawer_close
in your strings.xml?I think you didn't add these two strings in your strings.