Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Adding Users Using Parse.com Logging Out

adnanalvee2
adnanalvee2
6,862 Points

Error while making item id!

I don't know why am I getting an error while trying create item in the OnOptionsMenuClosed method.

Here is a screenshot, http://s18.postimg.org/r6bfltg7d/togo.png

In Ben's video, this thing comes up at around 2:50.

1 Answer

Erin Kabbash
Erin Kabbash
5,210 Points

You are getting this error because the item you are passing to the OnOptionsMenuClosed method is named "menu" but inside the method the code is referring to it as "item". I believe Ben pulls a fast one and changes menu to item and it is hard to miss. Take a look at the following code and it should make more sense:

public boolean onOptionsItemSelected(MenuItem item) {

int itemId = item.getItemId();

}

See the declaration of the variable that is being passed? He changed it to "item" and in your code its listed as "menu". Hopefully that makes sense and helps. Happy Coding!!