Android R无法解析为变量,因此';解决不了

Android R无法解析为变量,因此';解决不了,android,r.java-file,Android,R.java File,有人能帮我吗 public class Maths4to5Home extends Activity implements OnClickListener { private Button button_4to5PlayGame, button_mathsInstructions, button_4to5Scores; protected void onCreate(Bundle savedInstanceState) {

有人能帮我吗

public class Maths4to5Home extends Activity implements OnClickListener 
    {
        private Button button_4to5PlayGame, button_mathsInstructions, button_4to5Scores;

        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_maths4to5home); //error

            button_4to5PlayGame = (Button)findViewById(R.id.button_4to5PlayGame); //error
            button_mathsInstructions = (Button)findViewById(R.id.button_mathsInstructions); //error
            button_4to5Scores = (Button)findViewById(R.id.button_4to5Scores); //error
我已经包含了上面的代码示例,并强调了我的错误所在。我经常被告知,
R
不能解析为变量。我试过清理和重建。此外,我还尝试导入
R
(正如快速修复建议的那样),但后来我被告知,例如在我的
setContentView()

activity_maths4to5home cannot be resolved or is not a field

任何帮助都将不胜感激

您需要导入正确的
R
——特别是您的项目。这是基于项目清单中的内容。如果您的清单将项目的包声明为
com.example.my_project
,那么您需要
导入com.example.my_project.R

如果您的活动已在项目包中,则不需要导入
R
。但是,您特别需要不导入
android.R


错误消息也可能是由于缺少R.java导致的。如果资源中的错误阻止生成R.java,就会发生这种情况。您应该检查您的任何资源文件中是否有错误。

您好。我试过了,但现在得到的信息是“导入com.example.develapment.R无法解决”。@user3578463-我怀疑这可能是个问题,并在我的回答中添加了一点关于这个问题的内容。检查您的资源中是否有错误(也检查包名称中是否有拼写错误)。如果您使用的是Eclipse,请检查您的项目文件夹中是否有
gen/
文件夹,以及它是否包含所需的R.java文件。我在这里完全不知所措:(有一个gen/文件夹,它没有R.java文件。@user3578463-在Problems视图(窗口>Show view>Problems)中查看。可能会出现资源文件错误,而这些错误不会显示在package explorer视图中。@user3578463-还有(如果您使用Eclipse)尝试右键单击Package Explorer中的项目,然后选择Android工具>修复项目属性。检查xml文件中是否存在细微错误。还要检查文件名中是否使用了无效字符,例如
-
或大写字母。