Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException on orientation change
    primarykey
    data
    text
    <p>I am implementing the new <code>DrawerLayout</code> in a new project. My code is almost verbatim from the <code>DrawerLayout</code> guide and works find until I change orientation. What happens on orientation change is that any View set via <code>findViewById</code> is returning null. In the below code Both <code>mDrawerList</code> and <code>mDrawerLayout</code> are null on orientation change, but not when Activity is first opened. </p> <p>I check for null value to prevent the <code>NullPointerException</code> but I receive another warning in LogCat:</p> <pre><code>05-22 20:56:08.375: W/PhoneWindow(16528): Previously focused view reported id 2130968626 during save, but can't be found during restore. </code></pre> <p>The Activity now loads but the DrawerLayout will no longer slide out from the left as before. What's wrong here?</p> <p>This is the method that my onCreate calls.</p> <pre><code>public void initializeDrawer() { // Get list of menu items from array resource mDrawerItems = getResources().getStringArray(R.array.nav_drawer_items); if (mDrawerList == null) mDrawerList = (ListView) findViewById(R.id.left_drawer); // Set the adapter for the listview mDrawerList.setAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.drawer_list_item, mDrawerItems)); // Set the lists click listener mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // Set up the action bar toggle listener to get the draw moving if (mDrawerLayout == null) mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to // onPrepareOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to // onPrepareOptionsMenu() } }; // Attach the listener mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload