07 Feb 2014, 17:59
Generic-user-small

angelica perez (1 post)

Hi, I am working on the Sudoku in Hello, Android and am having two problems that I feel are connected. In my Prefs.java file, I have this code:

package com.example.sudoku1; import android.os.Bundle; import android.preference.PreferenceActivity; public class Prefs extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); } } Eclipse highlights the “xml” in “R.xml.settings” and says “xml cannot be resolved or is not a field.”

In my Sudoku.java, I have this method:

@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.settings: startActivity(new Intent(this, Prefs.class)); return true; // More items go here (if any) … } return false; } Eclipse highlights “settings” in “case R.id.settings;” and says “settings cannot be resolved or is not a field.”

My Prefs ad Sudoku java files are located in the src folder. My settings.xml is located in my res/xml/ folder.

My import statements for sudoku are:

import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.content.Intent; import android.view.View; import android.view.View.OnClickListener;

For Prefs they are

import android.os.Bundle; import android.preference.PreferenceActivity;

Do you know what my error is?

  You must be logged in to comment