25 Jan 2013, 20:20
Generic-user-small

Miller Ridgeway (13 posts)

Hi, I am a bit new to Android programming, so I am looking for some advice. The problem is, I am on section 3.8 in creating the settings menu, I have all but one error worked out. In my eclipse, it says “settings cannot be resolved or is not a field”. I know this means it cannot locate settings, but I don’t know why. My code is as follows

public boolean onOptionsItemSelected(MenuItem item)
{
	switch(item.getItemId())
	{
	case R.id.settings:
		startActivity(new Intent(this, Prefs.class));
		return true;
	}//switch
	return false; 
}//boolean

It gives me an error on the case R.id.settings. My settings file is as follows

The settings file above is located in res/xml. However, I had to create the folder, it was not already there. Any help or input would be appreciated, thanks.

26 Jan 2013, 11:35
Generic-user-small

Gerry Miller (2 posts)

Is this a run time error? If so have you tried looking in the log - see section 3.10 (Debugging)

Also have you use @Override before your method definition?

26 Jan 2013, 17:37
Generic-user-small

Anthony Shaw (136 posts)

Miller, I think you may have either missed out or mis-typed the menu.xml from section 3.7, in particular the line

item android:id=”@+id/settings”

I think the above line is what generates R.id.settings

28 Jan 2013, 19:59
Generic-user-small

Miller Ridgeway (13 posts)

Thanks Anthony! I figured this problem out promptly after I posted this, but did not have access to internet. Regardless, thank you for your response.

28 Jan 2013, 20:21
Generic-user-small

Anthony Shaw (136 posts)

No problem, glad you’re moving forward again.

  You must be logged in to comment